public void Update_AnyEntity_RepositoryUpdatesEntity() { // Arrange var entity = new AnyEntity { Id = 1, AnyString = "AnyString" }; // Act var result = controller.Update(1, entity) as OkResult; // Assert result.Should().NotBeNull(); A.CallTo(() => repository.Update(1, entity)).MustHaveHappenedOnceExactly(); }
public void Update_AnyModel_ModelUpdated() { // Arrange string id = ObjectId.GenerateNewId().ToString(); var model = new AnyModel { Id = id, AnyString = "AnyString" }; // Act var result = _controller.Update(id, model) as OkResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(200); A.CallTo(() => _repository.Update(id, model)).MustHaveHappenedOnceExactly(); }
public async Task Update_UpdateForbidden_ReturnsForbidden() { // Arrange var restrictedController = new AnyAsyncReadOnlyController(repository, logger); int id = 1; var entity = new AnyEntity(); // Act var result = await restrictedController.Update(id, entity) as ObjectResult; // Assert result.Should().NotBeNull(); result.StatusCode.Should().Be(403); A.CallTo(() => repository.Update(id, entity)).MustNotHaveHappened(); }
public void Update_ExistingEntity_EntityUpdatedAsync() { // Arrange dbContext.AnyEntities.Add(new AnyEntity { Id = 1, AnyString = "AnyString" }); dbContext.SaveChanges(); var expected = new AnyEntity { AnyString = "AnyNewString" }; // Act repository.Update(1, expected); dbContext.SaveChanges(); // Assert dbContext.AnyEntities.First(e => e.Id == 1).AnyString.Should().BeEquivalentTo(expected.AnyString); }