Browse Source

add unit test cases for organization, patient, and provider controllers

main^2
unknown 1 year ago
parent
commit
42f3bbd919
1 changed files with 213 additions and 4 deletions
  1. +213
    -4
      Assignment3UnitTest/UnitTest1.cs

+ 213
- 4
Assignment3UnitTest/UnitTest1.cs View File

@ -8,6 +8,7 @@ using System;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks;
using Assignment3;
namespace Assignment3UnitTest
{
@ -26,9 +27,9 @@ namespace Assignment3UnitTest
}
[TestMethod]
[ExpectedException(typeof(StatusException))]
public async Task Immunization_GetPostUpdateDeleteAsync()
{
Immunization testImmunization = new Immunization()
{
Id = Guid.NewGuid(),
@ -51,7 +52,7 @@ namespace Assignment3UnitTest
//Get the created Immunization from the DB and check if it's equal to testImmunization
Assert.AreEqual(
controller.GetImmunization(testImmunization.Id).Result.Value,
controller.GetImmunization(testImmunization.Id).Result.Value, //GET the original `testImmunization` object
testImmunization
);
}
@ -73,12 +74,220 @@ namespace Assignment3UnitTest
//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
//Get the updated Immunization from the DB and check if the OfficialName changed correctly
Assert.AreEqual(
"OfficialChangedName123",
controller.GetImmunization(testImmunization.Id).Result.Value.OfficialName //The original `testImmunization` object, which has 1 property changed "OfficialName"
controller.GetImmunization(testImmunization.Id).Result.Value.OfficialName //GET The original `testImmunization` object, which has 1 property changed "OfficialName"
);
}
//DELETE
using (var context = new Assignment3Context(contextOptions))
{
var controller = new ImmunizationController(context);
//delete the immunization
await controller.DeleteImmunization(testImmunization.Id);
await controller.GetImmunization(testImmunization.Id); //Raise exception because it should be deleted.
}
}
[TestMethod]
[ExpectedException(typeof(StatusException))]
public async Task Organization_GetPostUpdateDeleteAsync()
{
Organization testOrganization = new Organization()
{
Id = Guid.NewGuid(),
Name = "OrganizationName",
Type = "Hospital",
Address = "123 Candycane Lane"
};
//POST
using (var context = new Assignment3Context(contextOptions))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var controller = new OrganizationController(context);
//Create the Organization defined by testOrganization
await controller.PostOrganization(testOrganization);
//Get the created testOrganization from the DB and check if it's equal to testOrganization
Assert.AreEqual(
controller.GetOrganization(testOrganization.Id).Result.Value, //GET the original `testOrganization` object
testOrganization
);
}
//PUT
using (var context = new Assignment3Context(contextOptions))
{
var controller = new OrganizationController(context);
Organization testChangedOrganization = new Organization()
{
Id = testOrganization.Id,
Name = testOrganization.Name,
Type = testOrganization.Type,
Address = "123 Candycane Road"
};
//Update testOrganization to be testChangedOrganization
await controller.PutOrganization(testOrganization.Id, testChangedOrganization);
//Get the updated Organization from the DB and check if the Address changed correctly
Assert.AreEqual(
"123 Candycane Road",
controller.GetOrganization(testOrganization.Id).Result.Value.Address //GET The original `testOrganization` object, which has 1 property changed "Address"
);
}
//DELETE
using (var context = new Assignment3Context(contextOptions))
{
var controller = new OrganizationController(context);
//delete the organization
await controller.DeleteOrganization(testOrganization.Id);
await controller.GetOrganization(testOrganization.Id); //Raise exception because it should be deleted.
}
}
[TestMethod]
[ExpectedException(typeof(StatusException))]
public async Task Patient_GetPostUpdateDeleteAsync()
{
Patient testPatient = new Patient()
{
Id = Guid.NewGuid(),
FirstName = "Michael",
LastName = "Helbert",
DateOfBirth = new DateTime(1999, 06, 04)
};
//POST
using (var context = new Assignment3Context(contextOptions))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var controller = new PatientController(context);
//Create the Patient defined by testPatient
await controller.PostPatient(testPatient);
//Get the created Patient from the DB and check if it's equal to testPatient
Assert.AreEqual(
controller.GetPatient(testPatient.Id).Result.Value, //GET the original `testPatient` object
testPatient
);
}
//PUT
using (var context = new Assignment3Context(contextOptions))
{
var controller = new PatientController(context);
Patient testChangedPatient = new Patient()
{
Id = testPatient.Id,
FirstName = "Bob",
LastName = testPatient.LastName,
DateOfBirth = testPatient.DateOfBirth
};
//Update testPatient to be testChangedPatient
await controller.PutPatient(testPatient.Id, testChangedPatient);
//Get the updated Patient from the DB and check if the Address changed correctly
Assert.AreEqual(
"Bob",
controller.GetPatient(testPatient.Id).Result.Value.FirstName //GET The original `testPatient` object, which has 1 property changed "Address"
);
}
//DELETE
using (var context = new Assignment3Context(contextOptions))
{
var controller = new PatientController(context);
//delete the Patient
await controller.DeletePatient(testPatient.Id);
await controller.GetPatient(testPatient.Id); //Raise exception because it should be deleted.
}
}
[TestMethod]
[ExpectedException(typeof(StatusException))]
public async Task Provider_GetPostUpdateDeleteAsync()
{
Provider testProvider = new Provider()
{
Id = Guid.NewGuid(),
FirstName = "Kelly",
LastName = "Shelly",
LicenseNumber = 321123,
Address = "550 Cookiedough Drive"
};
//POST
using (var context = new Assignment3Context(contextOptions))
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var controller = new ProviderController(context);
//Create the Provider defined by testProvider
await controller.PostProvider(testProvider);
//Get the created Provider from the DB and check if it's equal to testProvider
Assert.AreEqual(
controller.GetProvider(testProvider.Id).Result.Value, //GET the original `testProvider` object
testProvider
);
}
//PUT
using (var context = new Assignment3Context(contextOptions))
{
var controller = new ProviderController(context);
Provider testChangedProvider = new Provider()
{
Id = testProvider.Id,
FirstName = testProvider.FirstName,
LastName = "Delly",
LicenseNumber = testProvider.LicenseNumber,
Address = testProvider.Address
};
//Update testProvider to be testChangedProvider
await controller.PutProvider(testProvider.Id, testChangedProvider);
//Get the updated Provider from the DB and check if the Address changed correctly
Assert.AreEqual(
"Delly",
controller.GetProvider(testProvider.Id).Result.Value.LastName //GET The original `testProvider` object, which has 1 property changed "lastName"
);
}
//DELETE
using (var context = new Assignment3Context(contextOptions))
{
var controller = new ProviderController(context);
//delete the Patient
await controller.DeleteProvider(testProvider.Id);
await controller.GetProvider(testProvider.Id); //Raise exception because it should be deleted.
}
}
}
}

Loading…
Cancel
Save