Beispiel #1
0
        private LicenseCategoryEntity MapLicenseCategoryModelToEntity(LicenseCategory model, LicenseCategoryEntity entity = null)
        {
            if (entity == null)
            {
                entity = new LicenseCategoryEntity();
            }

            entity.Code = model.Code;
            entity.Name = model.Name;

            return(entity);
        }
        public async Task GetLicenseCategories()
        {
            var options = TestHelper.GetDbContext("GetLicenseCategories");

            //Given
            var lkp1 = new LicenseCategoryEntity {
                Id = Guid.NewGuid(), Name = "A", Code = "1.0"
            };
            var lkp2 = new LicenseCategoryEntity {
                Id = Guid.NewGuid(), Name = "B", Code = "2.0"
            };
            var lkp3 = new LicenseCategoryEntity {
                Id = Guid.NewGuid(), Name = "C", Code = "3.0"
            };

            using (var context = new DataContext(options))
            {
                //Jumbled order
                context.LicenseCategory.Add(lkp2);
                context.LicenseCategory.Add(lkp1);
                context.LicenseCategory.Add(lkp3);

                context.SaveChanges();
            }

            using (var context = new DataContext(options))
            {
                var service = new DirectoryLookupService(context);

                //When
                var actual = await service.GetLicenseCategories();

                //Then
                Assert.Equal(3, actual.Count);

                var actual1 = actual[0];
                Assert.Equal(lkp1.Id, actual1.Id);
                Assert.Equal(lkp1.Name, actual1.Name);
                Assert.Equal(lkp1.Code, actual1.Code);

                var actual2 = actual[1];
                Assert.Equal(lkp2.Id, actual2.Id);

                var actual3 = actual[2];
                Assert.Equal(lkp3.Id, actual3.Id);
            }
        }
        public async Task UpdateLicenseCategory()
        {
            var options = TestHelper.GetDbContext("UpdateLicenseCategory");

            //Given
            var lkp1 = new LicenseCategoryEntity {
                Id = Guid.NewGuid(), Name = "1", Code = "A"
            };

            using (var context = new DataContext(options))
            {
                context.LicenseCategory.Add(lkp1);

                context.SaveChanges();
            }

            var model = new LicenseCategory()
            {
                Id   = lkp1.Id,
                Name = "1 Updated",
                Code = "A Updated",
            };

            using (var context = new DataContext(options))
            {
                var service = new DirectoryLookupService(context);

                //When
                var result = await service.UpdateLicenseCategory(model);

                //Then
                Assert.True(result.Success);

                var actual = await context.LicenseCategory.FindAsync(model.Id);

                Assert.Equal(model.Name, actual.Name);
                Assert.Equal(model.Code, actual.Code);
            }
        }