示例#1
0
        public async void DeleteErrorCanReturnNotFoundIfErrorNotFoundForGivenIDInDatabase()
        {
            DbContextOptions <BrokenAPIContext> options =
                new DbContextOptionsBuilder <BrokenAPIContext>()
                .UseInMemoryDatabase("deleteErrorIncorrectID")
                .Options;

            using (BrokenAPIContext context = new BrokenAPIContext(options))
            {
                // Arrange
                ErrorController ec = new ErrorController(context);

                Error newError = new Error
                {
                    ErrorCategoryID = 0,
                    DetailedName    = "Test",
                    Description     = "This is a testError.",
                    Link            = "test",
                    CodeExample     = "test",
                    IsUserExample   = false,
                    Votes           = 0,
                    Rating          = 0
                };

                await ec.PostError(newError);

                // Act
                var response = await ec.DeleteError(100);

                // Assert
                Assert.Equal("Microsoft.AspNetCore.Mvc.NotFoundResult", response.ToString());
            }
        }
示例#2
0
        public async void DeleteErrorCanRemoveAnErrorFromTheDatabaseAndReturnOk(string errorName)
        {
            DbContextOptions <BrokenAPIContext> options =
                new DbContextOptionsBuilder <BrokenAPIContext>()
                .UseInMemoryDatabase(errorName)
                .Options;

            using (BrokenAPIContext context = new BrokenAPIContext(options))
            {
                // Arrange
                ErrorController ec = new ErrorController(context);

                Error newError = new Error
                {
                    ErrorCategoryID = 0,
                    DetailedName    = errorName,
                    Description     = "This is a test.",
                    Link            = "test",
                    CodeExample     = "test",
                    IsUserExample   = false,
                    Votes           = 0,
                    Rating          = 0
                };

                await ec.PostError(newError);

                int errorID = 0;
                switch (errorName)
                {
                case "firstDeleteErrorTest":
                    errorID = 1;
                    break;

                case "secondDeleteErrorTest":
                    errorID = 2;
                    break;

                case "thirdDeleteErrorTest":
                    errorID = 3;
                    break;
                }

                // Act
                var response = await ec.DeleteError(errorID);

                var results = context.Errors.Where(e => e.DetailedName == errorName);

                // Assert
                Assert.Equal("Microsoft.AspNetCore.Mvc.OkResult", response.ToString());
                Assert.Equal(0, results.Count());
            }
        }