public async Task UpdatePurchaserReturnsBadResultIfSPurchaserAndIdDoNotMatch() { // arrange PurchaserService purchaserService = new PurchaserService(_client); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 0, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Purchaser createPurchaser = await purchaserService.CreatePurchaser(purchaser); // act var result = await _client.PutAsJsonAsync($"/api/purchasers/{2}", createPurchaser); // assert Assert.IsTrue(result.StatusCode == HttpStatusCode.BadRequest); await purchaserService.DeletePurchaserForProfile(createPurchaser.ProfileId); }
public async Task GetPurchasersReturnsExistingPurchasers() { // arrange PurchaserService purchaserService = new PurchaserService(_client); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 0, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; int expected = 1; Purchaser toDelete = await purchaserService.CreatePurchaser(purchaser); // act List <Purchaser> actual = await purchaserService.GetPurchasers(); // assert Assert.IsTrue(expected == actual.Count); await purchaserService.DeletePurchaserForProfile(toDelete.ProfileId); }
public async Task CreatePurchaser() { Purchaser purchaser = new Purchaser() { CountryId = Id, Profile = new Profile() }; purchaser.Profile.Username = Email; purchaser.Profile.Password = "******"; purchaser.Profile.Usertype = 1; Profile testProfile = await ProfileService.GetProfileByUsernameAndpassword(purchaser.Profile.Username, purchaser.Profile.Password); if (testProfile.Username == "") { await PurchaserService.CreatePurchaser(purchaser); NavigationManager.NavigateTo($"/user_view/{Id}", true); } else { _userAlreadyExists = $"A purchaser with the email '{Email}' already exists"; } }
public async Task DeletePurchaserForProfileDeletesThePurchaserIfItExists() { // arrange PurchaserService purchaserService = new PurchaserService(_client); CountryService countryService = new CountryService(_client); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country createdCountry = await countryService.CreateCountry(country); Purchaser createdPurchaser = await purchaserService.CreatePurchaser(purchaser); await purchaserService.DeletePurchaserForProfile(createdPurchaser.ProfileId); // act Purchaser expected = new Purchaser(); Purchaser actual = await purchaserService.GetPurchaser(createdPurchaser.ProfileId); // assert CollectionAssert.AreEquivalent(expected.Articles, actual.Articles); Assert.IsTrue(expected.Id == actual.Id); Assert.IsTrue(expected.CountryId == actual.CountryId); Assert.IsTrue(expected.ProfileId == actual.ProfileId); await countryService.DeleteCountry(createdCountry.Id); }
public async Task GetPurchasersForCountryReturnsPurchaserIfItExists() { // arrange PurchaserService purchaserService = new PurchaserService(_client); CountryService countryService = new CountryService(_client); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Country toDeleteCountry = await countryService.CreateCountry(country); Purchaser toDeletePurchaser = await purchaserService.CreatePurchaser(purchaser); int expected = 1; // act List <Purchaser> actual = await purchaserService.GetPurchasersForCountry(1); // assert Assert.IsTrue(actual.Count == expected); await purchaserService.DeletePurchaserForProfile(toDeletePurchaser.ProfileId); await countryService.DeleteCountry(toDeleteCountry.Id); }
public async Task UpdatePurchaserUpdatesExistingPurchaser() { // arrange PurchaserService purchaserService = new PurchaserService(_client); Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 0, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Purchaser expected = await purchaserService.CreatePurchaser(purchaser); expected.Profile.Password = "******"; await purchaserService.UpdatePurchaser(expected.Id, expected); // act Purchaser actual = await purchaserService.GetPurchaser(expected.Id); // assert Assert.IsTrue(expected.Country == actual.Country); Assert.IsTrue(expected.Id == actual.Id); CollectionAssert.AreEquivalent(expected.Articles, actual.Articles); Assert.IsTrue(expected.CountryId == actual.CountryId); Assert.IsTrue(expected.Id == actual.Id); Assert.IsTrue(expected.Profile.Id == actual.Profile.Id); Assert.IsTrue(expected.Profile.Password == actual.Profile.Password); CollectionAssert.AreEquivalent(expected.Profile.Purchasers, actual.Profile.Purchasers); Assert.IsTrue(expected.Profile.Username == actual.Profile.Username); CollectionAssert.AreEquivalent(expected.Profile.Purchasers, actual.Profile.Purchasers); Assert.IsTrue(expected.Profile.Usertype == actual.Profile.Usertype); CollectionAssert.AreEquivalent(expected.Profile.Countries, actual.Profile.Countries); Assert.IsTrue(expected.ProfileId == actual.ProfileId); await purchaserService.DeletePurchaserForProfile(expected.ProfileId); }
public async Task UpdateArticleUpdateTheGivenArticle() { // arrange ArticleService articleService = new ArticleService(_client); PurchaserService purchaserService = new PurchaserService(_client); CountryService countryService = new CountryService(_client); SupplierService supplierService = new SupplierService(_client); Article article = new Article() { Id = 0, PurchaserId = 1, CountryId = 1, SupplierId = 1, ArticleInformationId = 0, InternalArticleInformationId = 0, VailedForCustomer = "Customer", DateCreated = DateTime.Now, ArticleInformationCompleted = 0, InternalArticalInformationCompleted = 0, ArticleState = 0, ErrorReported = 0, ErrorField = "Field", ErrorMessage = "Message", ErrorOwner = "Owner", ArticleInformation = new ArticleInformation(), InternalArticleInformation = new InternalArticleInformation() }; Country country = new Country() { Id = 0, ProfileId = 0, CountryName = "Name", CountryCode = "Code", Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 0 } }; Purchaser purchaser = new Purchaser() { Id = 0, ProfileId = 0, CountryId = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Supplier supplier = new Supplier() { Id = 0, ProfileId = 0, CompanyName = "Name", CompanyLocation = "Location", FreightResponsibility = "EXW", PalletExchange = 1, Profile = new Profile() { Id = 0, Username = "******", Password = "******", Usertype = 2 } }; Country countryToDelete = await countryService.CreateCountry(country); purchaser.CountryId = countryToDelete.Id; Purchaser purchaserToDelete = await purchaserService.CreatePurchaser(purchaser); Supplier supplierToDelete = await supplierService.CreateSupplier(supplier); article.CountryId = countryToDelete.Id; article.SupplierId = supplierToDelete.Id; article.PurchaserId = purchaserToDelete.Id; Article expected = await articleService.CreateArticle(article); expected.ArticleState = 3; // act await articleService.UpdateArticle(expected.Id, expected); Article actual = await articleService.GetArticle(expected.Id); // assert Assert.IsTrue(expected.ArticleState == actual.ArticleState); List <Country> now = await countryService.GetCountries(); await articleService.DeleteArticle(expected.Id); await purchaserService.DeletePurchaserForProfile(purchaserToDelete.ProfileId); await supplierService.DeleteSupplier(supplierToDelete.Id); await countryService.DeleteCountry(countryToDelete.Id); await _context.DisposeAsync(); List <Country> late = await countryService.GetCountries(); }