Beispiel #1
0
        private AdviceScopeEntity MapAdviceScopeModelToEntity(AdviceScope model, AdviceScopeEntity entity = null)
        {
            if (entity == null)
            {
                entity = new AdviceScopeEntity();
            }

            entity.Name = model.Name;

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

            //Given
            var lkp1 = new AdviceScopeEntity {
                Id = Guid.NewGuid(), Name = "A"
            };
            var lkp2 = new AdviceScopeEntity {
                Id = Guid.NewGuid(), Name = "B"
            };
            var lkp3 = new AdviceScopeEntity {
                Id = Guid.NewGuid(), Name = "C"
            };

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

                context.SaveChanges();
            }

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

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

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

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

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

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

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

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

                context.SaveChanges();
            }

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

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

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

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

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

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