public void ShouldNotAddSuggestion() { // Arrange var mockSuggestionRepository = new Mock <ISuggestionRepository>(); mockSuggestionRepository.Setup(x => x.Get(42)) .Returns(new Suggestion { Id = 42 }); var mockBookingReposiroty = new Mock <IBookingRepository>(); Suggestion sugg = new Suggestion() { UserId = 1, Id = 42, Name = "Dit is een suggestie", NumberOfHours = 8.0, Description = "dit is een beschrijving", Milestone = "dit is een milestone", Type = BookingType.Training }; var sut = new SuggestionsController(mockSuggestionRepository.Object, mockBookingReposiroty.Object); // Act IActionResult actionResult = sut.AddSuggestion(sugg, 1); // Assert Assert.IsNotNull(actionResult); mockSuggestionRepository.Verify(mock => mock.Get(42)); mockSuggestionRepository.Verify(Mock => Mock.Add(sugg), Times.Never); }
public void ThreeValues_GreatestValueReturned() { // Arrange GreatestModifierTracker tracker = new Mock <GreatestModifierTracker> { CallBase = true }.Object; tracker.Add(() => 2); tracker.Add(() => 5); tracker.Add(() => 3); // Act byte total = tracker.GetTotal(); // Assert Assert.AreEqual(5, total, "Only the greatest value from a NonStackingBonusTracker should be returned."); }
public void ThreeValues_ReturnSum() { // Arrange SumModifierTracker tracker = new Mock <SumModifierTracker> { CallBase = true }.Object; tracker.Add(() => 1); tracker.Add(() => 2); tracker.Add(() => 3); // Act byte total = tracker.GetTotal(); // Assert Assert.AreEqual(6, total, "The sum of all values inside a StackingBonusTracker should be returned."); }
public void With_wrong_type_throws() { var set = new Mock<InternalContextForMock> { CallBase = true } .Object.Owner.Set(typeof(FakeEntity)); Assert.Equal( Strings.DbSet_BadTypeForAddAttachRemove("Add", "String", "FakeEntity"), Assert.Throws<ArgumentException>(() => set.Add("Bang!")).Message); }
public void With_wrong_type_throws() { var set = new Mock <InternalContextForMock> { CallBase = true } .Object.Owner.Set(typeof(FakeEntity)); Assert.Equal( Strings.DbSet_BadTypeForAddAttachRemove("Add", "String", "FakeEntity"), Assert.Throws <ArgumentException>(() => set.Add("Bang!")).Message); }
public void AddArea_ExpectError() { areaLogic.Setup(areaLogic => areaLogic.Add(area)).Throws(new ArgumentException("This area already exists")); var result = areaController.Post(areaModelIn); var createdResult = result as BadRequestObjectResult; areaLogic.VerifyAll(); Assert.IsNotNull(createdResult); Assert.AreEqual(400, createdResult.StatusCode); }
public void AddShouldRegisterNewUnitOfWorkItem() { // arrange var item = new object(); var unitOfWork = new Mock<IUnitOfWork<object>>(); unitOfWork.Setup( u => u.RegisterNew( It.IsAny<object>() ) ); var target = new Mock<Repository<object>>( unitOfWork.Object ) { CallBase = true }.Object; // act target.Add( item ); // assert unitOfWork.Verify( u => u.RegisterNew( item ), Times.Once() ); }
public async Task AddTask_WithValidModel_ReturnsStatusOk() { this.repositoryAccessors.Setup(ra => ra.ProjectRepository).Returns(() => this.projectRepository.Object); this.repositoryAccessors.Setup(ra => ra.MemberRepository).Returns(() => this.memberRepository.Object); this.repositoryAccessors.Setup(ra => ra.TaskRepository).Returns(() => this.taskRepository.Object); this.repositoryAccessors. Setup(repositoryAccessor => repositoryAccessor.SaveChangesAsync()). Returns(Task.FromResult(1)); var project = TestData.Projects.First(); this.projectRepository. Setup(projectRepository => projectRepository.GetAsync(It.IsAny <Guid>())). Returns(Task.FromResult(project)); this.memberRepository. Setup(memberRepository => memberRepository.GetAllActiveMembersAsync(It.IsAny <Guid>())). Returns(Task.FromResult(TestData.Members)); var taskDetails = TestData.Task; taskDetails.StartDate = project.StartDate; taskDetails.EndDate = project.EndDate; this.taskRepository. Setup(taskRepository => taskRepository.Add(It.IsAny <TaskEntity>())). Returns(taskDetails); var taskHelper = new TaskHelper(this.repositoryAccessors.Object, this.logger.Object); var userObjectId = Guid.Parse("82ab7412-f6c1-491d-be16-f797e6903667"); var addResult = await taskHelper.AddMemberTaskAsync(TestData.Task, Guid.Parse("1eec371f-edbe-4ad1-be1d-d4cd3515541e"), userObjectId); Assert.IsTrue(addResult != null); }