public void ThrowArgumentNullException_WhenTeamWithPassedAwayTeamNameIsNotPresent() { // arrange var fixtureRepo = new Mock <IEfRepository <Fixture> >(); var teamsRepo = new Mock <IEfRepository <Team> >(); var playersRepo = new Mock <IEfRepository <Player> >(); var fixturesFactory = new Mock <IFixturesFactory>(); var mailService = new Mock <IFixtureMailService>(); var teams = new List <Team>() { new Team() { Name = "presentName" } }; teamsRepo.Setup(r => r.All).Returns(teams.AsQueryable()); var fixtureService = new FixtureService( fixtureRepo.Object, teamsRepo.Object, playersRepo.Object, fixturesFactory.Object, mailService.Object); // act and assert Assert.Throws <ArgumentNullException>(() => fixtureService.Add("presentName", "notPresentNae", null)); }
private async Task AddFixture() { FixtureForAddDto fixtureForAddDto = new FixtureForAddDto() { CategoryId = (cmbCategory.SelectedItem as dynamic).Value, DatePurchase = dtpPurchase.Value.Date, DateWarranty = dtpWarranty.Value.Date, Description = txtDescription.Text, Name = txtName.Text, PictureUrl = "pic.lk", // TODO : picture link Price = Convert.ToDecimal(txtPrice.Text), SupplierId = (cmbSupplier.SelectedItem as dynamic).Value }; await FixtureService.Add(fixtureForAddDto); MessageBox.Show(Messages.FixtureAdded); await LoadFixtureList(); }
public void ThrowInvalidOperationException_WhenHomeAndAwayTeamsNameAreEqual() { // arrange var fixtureRepo = new Mock <IEfRepository <Fixture> >(); var teamsRepo = new Mock <IEfRepository <Team> >(); var playersRepo = new Mock <IEfRepository <Player> >(); var fixturesFactory = new Mock <IFixturesFactory>(); var mailService = new Mock <IFixtureMailService>(); var fixtureService = new FixtureService( fixtureRepo.Object, teamsRepo.Object, playersRepo.Object, fixturesFactory.Object, mailService.Object); // act and assert Assert.Throws <InvalidOperationException>(() => fixtureService.Add("sameName", "sameName", null)); }
public void CallFixturesRepositoryAddMethodWithFixtureReturnFromFactory_WhenPassedParametersAreValid() { // arrange var fixtureRepo = new Mock <IEfRepository <Fixture> >(); var teamsRepo = new Mock <IEfRepository <Team> >(); var playersRepo = new Mock <IEfRepository <Player> >(); var fixturesFactory = new Mock <IFixturesFactory>(); var mailService = new Mock <IFixtureMailService>(); var teams = new List <Team>() { new Team() { Name = "presentName" }, new Team() { Name = "AnotherPresentName" } }; teamsRepo.Setup(r => r.All).Returns(teams.AsQueryable()); var date = new DateTime?(new DateTime(2015, 1, 1)); var returnedFixture = new Fixture(); fixturesFactory.Setup(f => f.GetFixture(It.IsAny <Team>(), It.IsAny <Team>(), date)) .Returns(returnedFixture); fixtureRepo.Setup(fr => fr.Add(It.Is <Fixture>(f => f == returnedFixture))); var fixtureService = new FixtureService( fixtureRepo.Object, teamsRepo.Object, playersRepo.Object, fixturesFactory.Object, mailService.Object); fixtureService.Add("presentName", "AnotherPresentName", date); // assert fixtureRepo.Verify(fr => fr.Add(It.Is <Fixture>(f => f == returnedFixture)), Times.Once); }
public void CallFixturesFactoryGetFixtureWithCorrectParameters_WhenBothTeamsAreFoundInRepository() { // arrange var fixtureRepo = new Mock <IEfRepository <Fixture> >(); var teamsRepo = new Mock <IEfRepository <Team> >(); var playersRepo = new Mock <IEfRepository <Player> >(); var fixturesFactory = new Mock <IFixturesFactory>(); var mailService = new Mock <IFixtureMailService>(); var teams = new List <Team>() { new Team() { Name = "presentName" }, new Team() { Name = "AnotherPresentName" } }; teamsRepo.Setup(r => r.All).Returns(teams.AsQueryable()); var date = new DateTime?(new DateTime(2015, 1, 1)); var returnedFixture = new Fixture(); fixturesFactory.Setup(f => f.GetFixture(It.IsAny <Team>(), It.IsAny <Team>(), date)); var fixtureService = new FixtureService( fixtureRepo.Object, teamsRepo.Object, playersRepo.Object, fixturesFactory.Object, mailService.Object); fixtureService.Add("presentName", "AnotherPresentName", date); // assert fixturesFactory.Verify(f => f.GetFixture(teams[0], teams[1], date)); }