public async Task PostPlatform_CorrectPlatformWithCorrectValuesAndNonexistingIdSetted_CreatedAtActionResultWithSettedId() { // Arrange const int idToSet = 10; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Platform platformToCreate = new Platform() { Name = "NewDevelope", ID = idToSet }; // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); var result = (await platformsController.PostPlatform(platformToCreate)).Result; // Assert Assert.True(context.Platforms.Contains(platformToCreate)); Assert.True(platformToCreate.ID == idToSet); Assert.IsType <CreatedAtActionResult>(result); } }
public async Task PutPlatform_ExistingIdCorrectPlatformWithNameChanged_NoContentResult() { // Arrange const int platformId = 3; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Platform platformToUpdate = GetFakeList().Where(d => d.ID == platformId).FirstOrDefault(), // Should use ICopyable interface here expectedPlatform = GetFakeList().Where(d => d.ID == platformId).FirstOrDefault(); // Act using (var context = new GameReviewsContext(options)) { platformToUpdate.Name = "newName"; expectedPlatform.Name = "newName"; PlatformsController platformsController = new PlatformsController(context); var result = (await platformsController.PutPlatform(platformId, platformToUpdate)); Platform actualPlatform = await context.Platforms.Where(d => d.ID == platformId).FirstOrDefaultAsync(); // Assert Assert.True(AreEqual(expectedPlatform, actualPlatform)); Assert.IsType <NoContentResult>(result); } }
public async Task GetPlatform_NonexistentZeroId_NotFoundResult() { // Arrange const int platformId = 0; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); var result = (await platformsController.GetPlatform(platformId)).Result; // Assert Assert.IsType <NotFoundResult>(result); } }
public async Task DeletePlatform_NegativeId_NotFoundResult() { // Arrange const int platformIdToDelete = -10; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Platform expectedPlatform = GetFakeList().Where(d => d.ID == platformIdToDelete).FirstOrDefault(); // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); var actionResult = (await platformsController.DeletePlatform(platformIdToDelete)); var result = actionResult.Result; // Assert Assert.IsType <NotFoundResult>(result); } }
public async Task GetPlatform_ExistingId_TaskActionResultContainsPlatform() { // Arrange const int platformId = 3; Platform expectedPlatform = GetFakeList().Where(d => d.ID == platformId).FirstOrDefault(); InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); var actionResult = (await platformsController.GetPlatform(platformId)); Platform platform = actionResult.Value; ActionResult result = actionResult.Result; // Assert Assert.True(AreEqual(expectedPlatform, platform)); Assert.IsNotType <NotFoundResult>(result); } }
public async Task GetPlatforms_Void_TaskActionResultContainsIEnumerableOfPlatform() { // Arrange List <Platform> expectedData = GetFakeList(); InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); IEnumerable <Platform> platforms = (await platformsController.GetPlatforms()).Value; // Assert Assert.Equal(expectedData.Count, platforms.Count()); for (int i = 0; i < expectedData.Count; ++i) { Assert.True(AreEqual(expectedData[i], platforms.ElementAt(i))); } } }
public async Task PostPlatform_CorrectPlatformWithCorrectValuesAndNegativeIdSetted_BadRequestResult() { // Arrange const int idToSet = -1; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Platform platformToCreate = new Platform() { Name = "NewDevelope", ID = idToSet }; // Act using (var context = new GameReviewsContext(options)) { PlatformsController platformsController = new PlatformsController(context); var result = (await platformsController.PostPlatform(platformToCreate)).Result; // Assert Assert.IsType <BadRequestResult>(result); } }
public async Task PutPlatform_ExistingIdCorrectPlatformWithIdChangedNegative_BadRequestResult() { // Arrange const int platformId = 3, idChanged = -1; InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList()); Platform platformToUpdate = GetFakeList().Where(d => d.ID == platformId).FirstOrDefault(); // Act using (var context = new GameReviewsContext(options)) { platformToUpdate.ID = idChanged; PlatformsController platformsController = new PlatformsController(context); var result = (await platformsController.PutPlatform(platformId, platformToUpdate)); Platform actualPlatform = await context.Platforms.Where(d => d.ID == platformId).FirstOrDefaultAsync(); // Assert Assert.IsType <BadRequestResult>(result); } }
public PlatformsControllerTests() { _sut = new PlatformsController(_mockPlatformsService); }
public void TestInitalize() { fakePlatformRequestAggregate = A.Fake <IPlatformRequestAggregate>(); controller = new PlatformsController(fakePlatformRequestAggregate); }