public async Task GetUnfinishedBestellingenOfKlant() { var klant = new Klant { Voornaam = "Hans", Achternaam = "Van Huizen", Id = "1" }; var bestelling1 = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, }; var bestelling2 = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Middenhoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, }; var bestelling3 = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Hooghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.InBehandelingDoorMagazijn, }; using (var context = new BeheerContext(_options)) { var mapper = new KlantDatamapper(context); mapper.Insert(klant); var bestellingmapper = new BestellingDatamapper(context); await bestellingmapper.Insert(bestelling1); await bestellingmapper.Insert(bestelling2); await bestellingmapper.Insert(bestelling3); } using (var context = new BeheerContext(_options)) { var mapper = new KlantDatamapper(context); var bestellingen = await mapper.GetUnFinishedBestellingenOfKlant("1"); Assert.AreEqual(2, bestellingen.Count); Assert.IsTrue(bestellingen.Any(b => b.Plaats == "Laaghoven")); Assert.IsTrue(bestellingen.Any(b => b.Plaats == "Middenhoven")); Assert.IsFalse(bestellingen.Any(b => b.Plaats == "Hooghoven")); } }
public async Task GetVolgendeBestellingGivesNextBestelling() { var bestelling = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.GereedVoorBehandeling }; var bestelling2Finished = new Bestelling { KlantId = "1", AdresRegel1 = "Middenland 34", Plaats = "Middenhoven", Postcode = "4535FF", BestellingStatus = BestellingStatus.Verzonden }; var bestelling3 = new Bestelling { KlantId = "1", AdresRegel1 = "Hoogstraat 27", Plaats = "Hooghoven", Postcode = "4321PD", BestellingStatus = BestellingStatus.GereedVoorBehandeling }; using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Insert(bestelling); await mapper.Insert(bestelling2Finished); await mapper.Insert(bestelling3); } using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.GetFirstUndone(); Assert.AreEqual(1, result); //Should skip the second one var result2 = await mapper.GetFirstUndone(); Assert.AreEqual(3, result2); } }
public async Task FinishBestellingLowersVoorraad() { _magazijnCalled = 0; using (var context = new BeheerContext(options)) { var bestelling = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3), new BestellingItem(2, 5) } }; var datamapper = new BestellingDatamapper(context); await datamapper.Insert(bestelling); } var commandPublisher = new CommandPublisher(_context); var result = await commandPublisher.Publish <int>(new BestellingAfrondenCommand { Id = 1 }, NameConstants.FinishBestellingCommandQueue); Thread.Sleep(1000); Assert.AreEqual(2, _magazijnCalled); }
public async Task GetKlantWithBestellingIdReturnsKlant() { var klant = new Klant { Voornaam = "Hans", Achternaam = "Van Huizen", Id = "1" }; var bestelling = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, }; using (var context = new BeheerContext(_options)) { var mapper = new KlantDatamapper(context); mapper.Insert(klant); var bestellingmapper = new BestellingDatamapper(context); await bestellingmapper.Insert(bestelling); } using (var context = new BeheerContext(_options)) { var mapper = new KlantDatamapper(context); var resultKlant = await mapper.GetKlantWithBestellingId(1); Assert.AreEqual("1", resultKlant.Id); Assert.AreEqual("Van Huizen", resultKlant.Achternaam); Assert.AreEqual("Hans", resultKlant.Voornaam); } }
public async Task InsertBestellingIntoDatabaseAndUpdate() { var bestelling = new Bestelling { Id = 1, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3) { Id = 1 }, new BestellingItem(2, 5) { Id = 2 } } }; using (var context = new WebshopContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Insert(bestelling); } using (var context = new WebshopContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.Get(1); Assert.AreEqual("1", result.KlantId); Assert.AreEqual("Laagstraat 11", result.AdresRegel1); Assert.AreEqual("Laaghoven", result.Plaats); Assert.AreEqual("1234FG", result.Postcode); Assert.AreEqual(2, result.BesteldeArtikelen.Count); Assert.IsTrue(result.BesteldeArtikelen.Any(b => b.Artikel.Naam == "Fiets" && b.Aantal == 3)); result.BestellingStatus = BestellingStatus.GereedVoorBehandeling; using (var context2 = new WebshopContext(_options)) { var mapper2 = new BestellingDatamapper(context2); await mapper2.Update(result); } } using (var context = new WebshopContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.Get(1); Assert.AreEqual(BestellingStatus.GereedVoorBehandeling, result.BestellingStatus); } }
public async Task KeurBestellingGoedChangesBestellingToGereedVoorBehandeling() { using (var context = new BeheerContext(options)) { var bestelling = new Bestelling { Id = 1, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3) { Id = 1 }, new BestellingItem(2, 5) { Id = 2 } } }; var datamapper = new BestellingDatamapper(context); await datamapper.Insert(bestelling); } var commandPublisher = new CommandPublisher(_context); await commandPublisher.Publish <int>(new BestellingGoedkeurenCommand { Id = 1 }, NameConstants.BestellingGoedKeurenCommandQueue); Thread.Sleep(1000); using (var context = new BeheerContext(options)) { var datamapper = new BestellingDatamapper(context); var result = await datamapper.GetBestelling(1); Assert.AreEqual(BestellingStatus.GereedVoorBehandeling, result.BestellingStatus); var klantmapper = new KlantDatamapper(context); var klant = await klantmapper.GetKlant("1"); } }
public async Task UpdateBestellingUpdatesIntoDatabase() { var bestelling = new Bestelling { KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3), new BestellingItem(2, 5) } }; using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Insert(bestelling); } bestelling.BestellingStatus = BestellingStatus.GereedVoorBehandeling; using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Update(bestelling); } using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.GetBestelling(1); Assert.AreEqual(BestellingStatus.GereedVoorBehandeling, result.BestellingStatus); } }
public async Task InsertBestellingIntoDatabase() { var bestelling = new Bestelling { BestellingStatus = BestellingStatus.GereedVoorBehandeling, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3), new BestellingItem(2, 5) } }; using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Insert(bestelling); } using (var context = new BeheerContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.GetBestelling(1); Assert.AreEqual("Hans", result.Klant.Voornaam); Assert.AreEqual("Van Huizen", result.Klant.Achternaam); Assert.AreEqual("1", result.KlantId); Assert.AreEqual("Laagstraat 11", result.AdresRegel1); Assert.AreEqual("Laaghoven", result.Plaats); Assert.AreEqual("1234FG", result.Postcode); Assert.AreEqual(2, result.BesteldeArtikelen.Count); Assert.AreEqual(BestellingStatus.GereedVoorBehandeling, result.BestellingStatus); Assert.IsTrue(result.BesteldeArtikelen.Any(b => b.Artikel.Naam == "Fiets" && b.Aantal == 3)); } }
public async Task VolgendeBestellingInpakkenGivesVolgendeBestellingSetsStatusToInbehandeling() { using (var context = new BeheerContext(options)) { var bestelling = new Bestelling { BestellingStatus = BestellingStatus.GereedVoorBehandeling, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3), new BestellingItem(2, 5) } }; var bestelling2 = new Bestelling { BestellingStatus = BestellingStatus.GereedVoorBehandeling, KlantId = "1", AdresRegel1 = "Hoogstraat 77", Plaats = "Hooghoven", Postcode = "4321FE", BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 3), new BestellingItem(2, 5) } }; var datamapper = new BestellingDatamapper(context); await datamapper.Insert(bestelling); await datamapper.Insert(bestelling2); } var commandPublisher = new CommandPublisher(_context); var result = await commandPublisher.Publish <int>(new VolgendeBestellingCommand(), NameConstants.VolgendeBestellingCommandQueue); Assert.AreEqual(1, result); var result2 = await commandPublisher.Publish <int>(new VolgendeBestellingCommand(), NameConstants.VolgendeBestellingCommandQueue); Assert.AreEqual(2, result2); var resultShouldbeZero = await commandPublisher.Publish <int>(new VolgendeBestellingCommand(), NameConstants.VolgendeBestellingCommandQueue); Assert.AreEqual(0, resultShouldbeZero); using (var context = new BeheerContext(options)) { var bestellingDatamapper = new BestellingDatamapper(context); var bestelling = await bestellingDatamapper.GetBestelling(1); Assert.AreEqual(BestellingStatus.InBehandelingDoorMagazijn, bestelling.BestellingStatus); } }
public async Task GetBestellingenAbove500EurAndNotAcceptedBySalesOnlyReturnsThose() { var bestellingBoven500 = new Bestelling { Id = 1, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.TerControleVoorSales, BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(2, 1) { Id = 1 } } }; var bestellingOnder500 = new Bestelling { Id = 2, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.GereedVoorBehandeling, BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(1, 1) { Id = 2 } } }; var bestellingBoven500GereedVoorBehandeling = new Bestelling { Id = 3, KlantId = "1", AdresRegel1 = "Laagstraat 11", Plaats = "Laaghoven", Postcode = "1234FG", BestellingStatus = BestellingStatus.GereedVoorBehandeling, BesteldeArtikelen = new List <BestellingItem> { new BestellingItem(2, 1) { Id = 3 } } }; using (var context = new WebshopContext(_options)) { var mapper = new BestellingDatamapper(context); await mapper.Insert(bestellingBoven500); await mapper.Insert(bestellingOnder500); await mapper.Insert(bestellingBoven500GereedVoorBehandeling); } using (var context = new WebshopContext(_options)) { var mapper = new BestellingDatamapper(context); var result = await mapper.GetBestellingenBoven500() as List <Bestelling>; Assert.IsTrue(result.Any(b => b.Id == bestellingBoven500.Id)); Assert.IsFalse(result.Any(b => b.Id == bestellingOnder500.Id)); Assert.IsFalse(result.Any(b => b.Id == bestellingBoven500GereedVoorBehandeling.Id)); } }