public void ValidateAnnouncement_ValidSections_ReturnsTrueWithNoError() { var validator = new AnnouncementValidator(); var modelErrors = new MockErrorCollection(); var result = validator.ValidateAnnouncement ( new Classroom() { Sections = Collections.CreateList ( new Section() { Id = 1 } ) }, new Announcement() { Sections = Collections.CreateList ( new AnnouncementSection() { SectionId = 1 } ) }, modelErrors ); Assert.True(result); Assert.False(modelErrors.HasErrors); }
public void ValidateAnnouncement_InvalidSection_ReturnsFalseWithError() { var validator = new AnnouncementValidator(); var modelErrors = new MockErrorCollection(); var result = validator.ValidateAnnouncement ( new Classroom() { Sections = new List <Section>() }, new Announcement() { Sections = Collections.CreateList ( new AnnouncementSection() { SectionId = 1 } ) }, modelErrors ); Assert.False(result); Assert.True(modelErrors.VerifyErrors("Sections")); }
public void UpdatesExistingAnnouncement() { Announcement announcement = new Announcement { AnnouncementId = 1, Title = "Title", Body = "Body", Deleted = false, Image = null }; //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(un => un.AnnouncementRepository.GetByID(It.IsAny <int>())) .Returns(announcement); //Además, seteamos las expectativas para los métodos que deben llamarse luego mockUnitOfWork.Setup(un => un.AnnouncementRepository.Update(It.IsAny <Announcement>())); mockUnitOfWork.Setup(un => un.Save()); AnnouncementValidator announcementValidator = new AnnouncementValidator(mockUnitOfWork.Object); //act announcementValidator.PutAnnouncement(1, announcement); //Assert mockUnitOfWork.Verify(un => un.AnnouncementRepository.Update(It.IsAny <Announcement>()), Times.Exactly(1)); mockUnitOfWork.Verify(un => un.Save(), Times.Exactly(1)); }
public static AnnouncementValidator GetAnnouncementValidatorInstance() { if (announcementValidator == null) { announcementValidator = new AnnouncementValidator(GetUnitOfWofkInstance()); } return(announcementValidator); }
public void GetAnnouncementById() { //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); //Esperamos que se llame al metodo Get del AnnouncementRepository con un int mockUnitOfWork.Setup(un => un.AnnouncementRepository.GetByID(It.IsAny <int>())); AnnouncementValidator announcementValidator = new AnnouncementValidator(mockUnitOfWork.Object); //Act Announcement returnedAnnouncement = announcementValidator.GetAnnouncement(5); //Assert //mockUnitOfWork.VerifyAll(); }
public void CreateAnnouncementTest() { //Arrange //Creo el mock object del unitOfWork var mockUnitOfWork = new Mock <IUnitOfWork>(); //Esperamos que se llame al método Insert del Repository con un Announcement y luego al Save(); mockUnitOfWork.Setup(un => un.AnnouncementRepository.Insert(It.IsAny <Announcement>())); mockUnitOfWork.Setup(un => un.Save()); AnnouncementValidator announcementValidator = new AnnouncementValidator(mockUnitOfWork.Object); //Act announcementValidator.PostAnnouncement(new Announcement()); //Assert mockUnitOfWork.VerifyAll(); }
public void DoesntUpdateNonExistingAnnouncement() { //Arrange var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork .Setup(un => un.AnnouncementRepository.GetByID(It.IsAny <int>())).Returns(() => null); mockUnitOfWork.Setup(un => un.AnnouncementRepository.Update(It.IsAny <Announcement>())); //mockUnitOfWork.Setup(un => un.Save()); IAnnouncementValidator announcementValidator = new AnnouncementValidator(mockUnitOfWork.Object); //act announcementValidator.PutAnnouncement(0, new Announcement() { }); //Assert //Retorna exception }