public void TestGetLocationTypeNotFound() { var connection = new SqliteConnection("Datasource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>() .UseSqlite(connection) .Options; // test a successful case using (var context = new InternalServicesDirectoryV1Context(options)) { context.Database.EnsureCreated(); context.LocationType.Add(new LocationType { LocationTypeName = "location1" }); context.SaveChanges(); LocationTypeController controller = new LocationTypeController(context); var actionResult = controller.Get(2).Result; var result = actionResult as NotFoundObjectResult; Assert.IsNotNull(result); Assert.AreEqual(404, result.StatusCode); Assert.AreEqual("No locationType from given id found.", result.Value); } } finally { connection.Close(); } }
public void TestPutLocationTypeNotFound() { var connection = new SqliteConnection("Datasource=:memory:"); connection.Open(); try { var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>() .UseSqlite(connection) .Options; // test a successful case using (var context = new InternalServicesDirectoryV1Context(options)) { context.Database.EnsureCreated(); var locationType = new LocationType { LocationTypeName = "locationType1" }; context.LocationType.Add(locationType); context.LocationType.Add(new LocationType { LocationTypeName = "locationType2" }); context.LocationType.Add(new LocationType { LocationTypeName = "locationType3" }); context.SaveChanges(); LocationTypeController controller = new LocationTypeController(context); locationType.LocationTypeId = 4; locationType.LocationTypeName = "locationType4"; var actionResult = controller.PutLocationType(locationType.LocationTypeId, locationType.ToLocationTypeV1DTO()).Result; var result = actionResult as NotFoundResult; Assert.IsNotNull(result); Assert.AreEqual(404, result.StatusCode); } } finally { connection.Close(); } }