Browse Source

test suite

main
unknown 1 year ago
parent
commit
a3293fc084
6 changed files with 109 additions and 5 deletions
  1. +7
    -1
      Assignment3.sln
  2. +2
    -2
      Assignment3/Migrations/20210314021900_init.Designer.cs
  3. +1
    -1
      Assignment3/Migrations/20210314021900_init.cs
  4. +2
    -1
      Assignment3/Models/Immunization.cs
  5. +21
    -0
      Assignment3UnitTest/Assignment3UnitTest.csproj
  6. +76
    -0
      Assignment3UnitTest/UnitTest1.cs

+ 7
- 1
Assignment3.sln View File

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29326.143
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assignment3", "Assignment3\Assignment3.csproj", "{131A1E29-55A1-412A-A3F8-E8F5E629960E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Assignment3", "Assignment3\Assignment3.csproj", "{131A1E29-55A1-412A-A3F8-E8F5E629960E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assignment3UnitTest", "Assignment3UnitTest\Assignment3UnitTest.csproj", "{B8B10FAF-98BC-4DFD-87FD-AA1D2FA2CC4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{131A1E29-55A1-412A-A3F8-E8F5E629960E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{131A1E29-55A1-412A-A3F8-E8F5E629960E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{131A1E29-55A1-412A-A3F8-E8F5E629960E}.Release|Any CPU.Build.0 = Release|Any CPU
{B8B10FAF-98BC-4DFD-87FD-AA1D2FA2CC4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8B10FAF-98BC-4DFD-87FD-AA1D2FA2CC4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8B10FAF-98BC-4DFD-87FD-AA1D2FA2CC4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8B10FAF-98BC-4DFD-87FD-AA1D2FA2CC4F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE


Assignment3/Migrations/20210313172309_init.Designer.cs → Assignment3/Migrations/20210314021900_init.Designer.cs View File

@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Assignment3.Migrations
{
[DbContext(typeof(Assignment3Context))]
[Migration("20210313172309_init")]
[Migration("20210314021900_init")]
partial class init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -47,7 +47,7 @@ namespace Assignment3.Migrations
.HasColumnType("nvarchar(128)")
.HasMaxLength(128);
b.Property<DateTimeOffset>("UpdatedTime")
b.Property<DateTimeOffset?>("UpdatedTime")
.HasColumnType("datetimeoffset");
b.HasKey("Id");

Assignment3/Migrations/20210313172309_init.cs → Assignment3/Migrations/20210314021900_init.cs View File

@ -17,7 +17,7 @@ namespace Assignment3.Migrations
TradeName = table.Column<string>(maxLength: 128, nullable: true),
LotNumber = table.Column<string>(maxLength: 255, nullable: false),
ExpirationDate = table.Column<DateTimeOffset>(nullable: false),
UpdatedTime = table.Column<DateTimeOffset>(nullable: false)
UpdatedTime = table.Column<DateTimeOffset>(nullable: true)
},
constraints: table =>
{

+ 2
- 1
Assignment3/Models/Immunization.cs View File

@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;


+ 21
- 0
Assignment3UnitTest/Assignment3UnitTest.csproj View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
<PackageReference Include="coverlet.collector" Version="1.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Assignment3\Assignment3.csproj" />
</ItemGroup>
</Project>

+ 76
- 0
Assignment3UnitTest/UnitTest1.cs View File

@ -0,0 +1,76 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Assignment3.Models;
using Assignment3.Controllers;
using System.Collections.Generic;
using Assignment3.Data;
using Microsoft.EntityFrameworkCore;
using System;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
namespace Assignment3UnitTest
{
[TestClass]
public class UnitTest1
{
DbContextOptions<Assignment3Context> contextOptions;
public UnitTest1()
{
string testDB = "Server=(localdb)\\MSSQLLocalDB;Database=Assignment3Context;Trusted_Connection=True;MultipleActiveResultSets=true";
this.contextOptions = new DbContextOptionsBuilder<Assignment3Context>()
.UseSqlServer(testDB)
.EnableSensitiveDataLogging().Options;
}
[TestMethod]
public async Task Immunization_GetPostUpdateDeleteAsync()
{
using (var context = new Assignment3Context(contextOptions))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var controller = new ImmunizationController(context);
//POST
Immunization testImmunization = new Immunization()
{
Id = Guid.NewGuid(),
OfficialName = "OfficialName123",
TradeName = "TradeName321",
LotNumber = "a1234",
ExpirationDate = new DateTime(2005, 06, 04),
};
//Create the Immunization defined by testImmunization
await controller.PostImmunization(testImmunization);
//Get the created Immunization from the DB and check if it's equal to testImmunization
Assert.AreEqual(
controller.GetImmunization(testImmunization.Id).Result.Value,
testImmunization
);
Immunization testChangedImmunization = new Immunization()
{
OfficialName = "OfficialChangedName123",
TradeName = testImmunization.TradeName,
LotNumber = testImmunization.LotNumber,
ExpirationDate = testImmunization.ExpirationDate,
};
//Update testImmunization to be testChangedImmunization
await controller.PutImmunization(testImmunization.Id, testChangedImmunization);
//Get the updated Immunization from the DB and check if the OfficialName is not the same as testImmunization
Assert.AreEqual(
"OfficialChangedName123",
controller.GetImmunization(testImmunization.Id).Result.Value.OfficialName //The original `testImmunization` object, which has 1 property changed "OfficialName"
);
}
}
}
}

Loading…
Cancel
Save