示例#1
0
        public async Task <IActionResult> SingleItem(string key)
        {
            int id            = Int32.Parse(key);
            var statusMessage = await logicValidation.CheckGetSingleDataModelAsync(id);

            if (statusMessage.IsCompleted)
            {
                var model = await logic.GetSingleDataModelAsync(id);

                return(View(model));
            }
            else
            {
                return(View("CustomError", statusMessage));
            }
        }
示例#2
0
        public async void GetStorageModel_FromInitializedDbTables_LogicStorageModelEqualExpectedStorageModel()
        {
            // arrange
            var productsCatalog = GetProductCatalogs();
            var storages        = GetStorages();
            var products        = GetProducts();
            var companies       = GetCompanies();

            fixture.db.Company.AddRange(companies);
            fixture.db.ProductCatalog.AddRange(productsCatalog);
            fixture.db.Storage.AddRange(storages);
            fixture.db.Product.AddRange(products);
            await fixture.db.SaveChangesAsync();

            var expected = new StorageModel
            {
                Id        = 44440,
                Name      = "Test storage #1",
                Latitude  = (decimal)12.3456,
                Longitude = (decimal)78.9012,
                Company   = new ValueTuple <string, int> {
                    Item1 = "Company #1", Item2 = 44440
                },
                Products = new List <ProductContainer>()
            };

            foreach (var product in products.Where(i => i.StorageId == expected.Id))
            {
                var productCatalog = productsCatalog.Single(i => product.Uid == i.Id);
                expected.Products.Add(new ProductContainer
                {
                    Id           = product.Id,
                    Uid          = productCatalog.Id,
                    Name         = productCatalog.Name,
                    Price        = product.Price,
                    Quantity     = product.Quantity,
                    QuantityUnit = product.QuantityUnit
                });
            }

            // act
            var actual = await logic.GetSingleDataModelAsync(expected.Id);

            // assert
            Assert.Equal(actual.Id, expected.Id);
            Assert.Equal(actual.Name, expected.Name);
            Assert.Equal(actual.Latitude, expected.Latitude);
            Assert.Equal(actual.Longitude, expected.Longitude);
            Assert.Equal(actual.Company.Item2, expected.Company.Item2);
            Assert.Equal(actual.Company.Item1, expected.Company.Item1);
            foreach (var expectedProduct in expected.Products)
            {
                Assert.Contains(actual.Products, actualProduct =>
                                actualProduct.Id == expectedProduct.Id &&
                                actualProduct.Uid == expectedProduct.Uid &&
                                actualProduct.Name == expectedProduct.Name &&
                                actualProduct.Price == expectedProduct.Price &&
                                actualProduct.Quantity == expectedProduct.Quantity &&
                                actualProduct.QuantityUnit == expectedProduct.QuantityUnit);
            }
        }