Пример #1
0
        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();
            }
        }