Exemplo n.º 1
0
        public async void NewArticleAdded()
        {
            if (CountryName != null && PurchaserUsername != null)
            {
                Country country = await CountryService.GetCountryWithName(CountryName);

                Profile profile = await ProfileService.GetProfileByUsernameAndpassword(PurchaserUsername, "1234");

                Purchaser purchaser = await PurchaserService.GetPurchaserForProfile(profile.Id);

                Article Article = new Article()
                {
                    PurchaserId                = purchaser.Id,
                    SupplierId                 = Id,
                    CountryId                  = country.Id,
                    VailedForCustomer          = ValidForCustomer,
                    DateCreated                = DateTime.Now,
                    ArticleState               = (int)ArticleState.Created,
                    ArticleInformation         = new ArticleInformation(),
                    InternalArticleInformation = new InternalArticleInformation()
                };

                Article.ArticleInformation.CompanyName           = Supplier.CompanyName;
                Article.ArticleInformation.CompanyLocation       = Supplier.CompanyLocation;
                Article.ArticleInformation.FreightResponsibility = Supplier.FreightResponsibility;
                Article.ArticleInformation.PalletExchange        = Supplier.PalletExchange;
                Article.ArticleInformation.Email = Supplier.Profile.Username;

                Article newArticle = await ArticleService.CreateArticle(Article);

                NavigationManager.NavigateTo($"/supplier_info_form/{newArticle.ArticleInformation.Id}", true);
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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";
            }
        }
Exemplo n.º 5
0
        public async Task UpdateFields()
        {
            Country country = await CountryService.GetCountryWithName(CountryName);

            Purchasers = await PurchaserService.GetPurchasersForCountry(country.Id);

            Customers = await VailedForCustomerService.GetVailedCustomers(country.Id);
        }
Exemplo n.º 6
0
        public async void DeleteProfile()
        {
            int       profileId = Profiles[0].Id;
            Purchaser purchaser = await PurchaserService.GetPurchaserForProfile(profileId);

            await PurchaserService.DeletePurchaserForProfile(ProfileClicked);

            NavigationManager.NavigateTo($"/user_view/{purchaser.CountryId}", true);
        }
Exemplo n.º 7
0
        protected async override Task OnInitializedAsync()
        {
            List <Purchaser> purchasers = await PurchaserService.GetPurchasersForCountry(1);

            Profiles = new List <Profile>();

            foreach (Purchaser purchaser in purchasers)
            {
                Profiles.Add(purchaser.Profile);
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public async Task GetPurchasersReturnsNewPurchaserListIfNoneExist()
        {
            // arrange
            PurchaserService purchaserService = new PurchaserService(_client);
            List <Purchaser> expected         = new List <Purchaser>();

            // act
            var actual = await purchaserService.GetPurchasers();

            // assert
            Assert.IsTrue(actual.Count == 0);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        public async Task GetPurchaserForProfileReturnsNewPurchaserIfNotExist()
        {
            // arrange
            PurchaserService purchaserService = new PurchaserService(_client);
            Purchaser        expected         = new Purchaser();

            // act
            Purchaser actual = await purchaserService.GetPurchaserForProfile(0);

            // 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.ProfileId == actual.ProfileId);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        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();
        }