示例#1
0
        public async Task GetByOrderIdAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceInfoRepo = new EfDeletableEntityRepository <ServiceInfo>(dbContext);

            var simRepo = new EfDeletableEntityRepository <SimCard>(dbContext);

            var moqServiceNumberService = new Mock <IServiceNumberService>();

            var service = new ServiceInfoService(
                serviceInfoRepo,
                simRepo,
                moqServiceNumberService.Object);

            var orderId = Guid.NewGuid().ToString();
            var model   = new ServiceInfoModel();

            var createdServiceInfo = await service.CreateAsync <ServiceInfoModel>(orderId, model, string.Empty);

            var serviceInfo = await service.GetByOrderIdAsync <ServiceInfoModel>(orderId);

            Assert.Equal(orderId, serviceInfo.OrderId);
            Assert.Equal(createdServiceInfo.Id, serviceInfo.Id);
        }
示例#2
0
        public async Task GetAllByCustomerIdAsyncShouldWorkCorrectlyWithServiceType()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceInfoRepo = new EfDeletableEntityRepository <ServiceInfo>(dbContext);

            var simRepo = new EfDeletableEntityRepository <SimCard>(dbContext);

            var moqServiceNumberService = new Mock <IServiceNumberService>();

            var service = new ServiceInfoService(
                serviceInfoRepo,
                simRepo,
                moqServiceNumberService.Object);

            var customerId = Guid.NewGuid().ToString();
            var orderId    = Guid.NewGuid().ToString();
            var model      = new ServiceInfoModel
            {
                CustomerId = customerId,
                IsActive   = true,
            };
            var createdServiceInfo = await service.CreateAsync <ServiceInfoModel>(orderId, model, string.Empty);

            var serviceInfos = await service.GetAllByCustomerIdAsync <ServiceInfoModel>(customerId);

            Assert.Single(serviceInfos);
            Assert.Collection(
                serviceInfos,
                x => Assert.Equal(customerId, x.CustomerId));
        }
示例#3
0
        public async Task ContractCancelAsyncShouldWorkCorrectlyWithServiceType()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceInfoRepo = new EfDeletableEntityRepository <ServiceInfo>(dbContext);

            var simRepo = new EfDeletableEntityRepository <SimCard>(dbContext);

            var moqServiceNumberService = new Mock <IServiceNumberService>();

            var service = new ServiceInfoService(
                serviceInfoRepo,
                simRepo,
                moqServiceNumberService.Object);

            var orderId = Guid.NewGuid().ToString();
            var model   = new ServiceInfoModel
            {
                IsActive = true,
            };
            var createdServiceInfo = await service.CreateAsync <ServiceInfoModel>(orderId, model, string.Empty);

            await service.ContractCancelAsync(1, string.Empty);

            var serviceInfo = await service.GetByIdAsync <ServiceInfoModel>(1);

            Assert.False(serviceInfo.IsActive);
        }
示例#4
0
        public async Task SetServiceAsActiveAsyncShouldWorkCorrectly()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceInfoRepo = new EfDeletableEntityRepository <ServiceInfo>(dbContext);

            var simRepo = new EfDeletableEntityRepository <SimCard>(dbContext);

            var moqServiceNumberService = new Mock <IServiceNumberService>();

            var service = new ServiceInfoService(
                serviceInfoRepo,
                simRepo,
                moqServiceNumberService.Object);

            var orderId = Guid.NewGuid().ToString();

            await simRepo.AddAsync(new SimCard
            {
                ICC = "89359032201234567890",
            });

            await simRepo.SaveChangesAsync();

            var model = new ServiceInfoModel
            {
                ICC = "89359032201234567890",
            };

            var serviceInfo = await service.CreateAsync <ServiceInfoModel>(orderId, model, string.Empty);

            await service.SetServiceAsActiveAsync(serviceInfo.Id);

            var serviceInfoForComp = await serviceInfoRepo.All()
                                     .FirstOrDefaultAsync(x => x.Id == serviceInfo.Id);

            var sims = await simRepo.All().ToListAsync();

            Assert.True(serviceInfoForComp.IsActive);
            Assert.Empty(sims);
        }
示例#5
0
        public async Task ExistByIdAsyncShouldReturnFalseWhenDoesNotExists()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options;
            var dbContext = new ApplicationDbContext(options);

            var serviceInfoRepo = new EfDeletableEntityRepository <ServiceInfo>(dbContext);

            var simRepo = new EfDeletableEntityRepository <SimCard>(dbContext);

            var moqServiceNumberService = new Mock <IServiceNumberService>();

            var service = new ServiceInfoService(
                serviceInfoRepo,
                simRepo,
                moqServiceNumberService.Object);

            var orderId            = Guid.NewGuid().ToString();
            var model              = new ServiceInfoModel();
            var createdServiceInfo = await service.CreateAsync <ServiceInfoModel>(orderId, model, string.Empty);

            Assert.False(await service.ExistByIdAsync(2));
        }