예제 #1
0
        public async Task DeleteClientPropertyAsync()
        {
            using (var context = new AdminDbContext(_dbContextOptions, _storeOptions, _operationalStore))
            {
                IClientRepository clientRepository = new ClientRepository(context);

                var localizerMock = new Mock <IClientServiceResources>();
                var localizer     = localizerMock.Object;

                IClientService clientService = new ClientService(clientRepository, localizer);

                //Generate random new client
                var client = ClientDtoMock.GenerateRandomClient(0);

                await clientService.AddClientAsync(client);

                //Get new client
                var clientEntity =
                    await context.Clients.Where(x => x.ClientId == client.ClientId).SingleOrDefaultAsync();

                var clientDto = await clientService.GetClientAsync(clientEntity.Id);

                //Assert new client
                client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id));

                //Generate random new Client Property
                var clientProperty = ClientDtoMock.GenerateRandomClientProperty(0, clientEntity.Id);

                //Add new client Property
                await clientService.AddClientPropertyAsync(clientProperty);

                //Get inserted client Property
                var property = await context.ClientProperties.Where(x => x.Value == clientProperty.Value && x.Client.Id == clientEntity.Id)
                               .SingleOrDefaultAsync();

                //Map entity to model
                var propertiesDto = property.ToModel();

                //Get new client Property
                var clientPropertiesDto = await clientService.GetClientPropertyAsync(property.Id);

                //Assert
                clientPropertiesDto.ShouldBeEquivalentTo(propertiesDto, options => options.Excluding(o => o.ClientPropertyId));

                //Delete client Property
                await clientService.DeleteClientPropertyAsync(clientPropertiesDto);

                //Get removed client Property
                var deletedClientProperty = await context.ClientProperties.Where(x => x.Id == property.Id).SingleOrDefaultAsync();

                //Assert after delete it
                deletedClientProperty.Should().BeNull();
            }
        }
예제 #2
0
        public async Task DeleteClientPropertyAsync()
        {
            IClientRepository clientRepository = new ClientDapperRepository(_configuration);

            var localizerMock = new Mock <IClientServiceResources>();
            var localizer     = localizerMock.Object;

            IClientService clientService = new ClientService(clientRepository, localizer);

            //Generate random new client
            var client = ClientDtoMock.GenerateRandomClient(0);

            var clientId = await clientService.AddClientAsync(client);

            //Get new client
            var clientEntity = await clientRepository.GetClientAsync(clientId);

            var clientDto = await clientService.GetClientAsync(clientEntity.Id);

            //Assert new client
            client.ShouldBeEquivalentTo(clientDto, options => options.Excluding(o => o.Id));

            //Generate random new Client Property
            var clientProperty = ClientDtoMock.GenerateRandomClientProperty(0, clientEntity.Id);

            //Add new client Property
            var clientPropertyId = await clientService.AddClientPropertyAsync(clientProperty);

            //Get inserted client property
            var property = await clientRepository.GetClientPropertyAsync(clientPropertyId);

            //Map entity to model
            var propertiesDto = property.ToModel();

            //Get new client Property
            var clientPropertiesDto = await clientService.GetClientPropertyAsync(property.Id);

            //Assert
            clientPropertiesDto.ShouldBeEquivalentTo(propertiesDto, options => options.Excluding(o => o.ClientPropertyId));

            //Delete client Property
            await clientService.DeleteClientPropertyAsync(clientPropertiesDto);

            //Get removed client Property
            var deletedClientProperty = await clientRepository.GetClientPropertyAsync(property.Id);

            //Assert after delete it
            deletedClientProperty.Should().BeNull();
        }