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

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

                var viewModel = LicensesDataModelToViewModel(dataModel);

                // gather licenses related to current license by product id
                var relatedLicensesDataModel = await logic.GetRelatedEntitiesByKeyAsync(dataModel.ProductId, id);

                var relatedLicensesViewModel = new List <LicensesViewModel>();
                foreach (var licenseDataModel in relatedLicensesDataModel)
                {
                    relatedLicensesViewModel.Add(LicensesDataModelToViewModel(licenseDataModel));
                }
                viewModel.RelatedLicenses = relatedLicensesViewModel;

                return(View(viewModel));
            }
            else
            {
                return(View("CustomError", statusMessage));
            }
        }
예제 #2
0
        public async void GetLicensesDataModel_FromInitializedDbTables_LogicLicensesDataModelEqualExpectedLicensesDataModel()
        {
            // arrange
            var products = GetProductsCatalog();
            var licenses = GetLicenses();

            fixture.db.ProductCatalog.AddRange(products);
            fixture.db.License.AddRange(licenses);
            await fixture.db.SaveChangesAsync();

            var expected = new LicensesDataModel
            {
                Id           = 44441,
                Date         = DateTime.UtcNow,
                GovermentNum = 4040414,
                ProductId    = 44440,
                ProductCAS   = 4040404,
                ProductName  = "Testin"
            };

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

            // assert
            Assert.Equal(actual.Id, expected.Id);
            Assert.Equal(actual.Date, expected.Date);
            Assert.Equal(actual.GovermentNum, expected.GovermentNum);
            Assert.Equal(actual.ProductId, expected.ProductId);
            Assert.Equal(actual.ProductCAS, expected.ProductCAS);
            Assert.Equal(actual.ProductName, expected.ProductName);
        }