예제 #1
0
        public ConsumptionServiceTest()
        {
            ContextOptions = new DbContextOptionsBuilder <SkrillaDbContext>()
                             .UseSqlite(CreateInMemoryDatabase())
                             .Options;

            _connection = RelationalOptionsExtension.Extract(ContextOptions).Connection;

            dbContext = new SkrillaDbContext(ContextOptions);
            dbContext.Database.EnsureDeleted();
            dbContext.Database.EnsureCreated();

            consumptionRequest = new ConsumptionRequest
            {
                Title    = "Example",
                Amount   = 123.4,
                Category = "ExampleCategory",
                Date     = new DateTime(2020, 05, 12)
            };

            category = new Category("ExampleCategory", false, "mockUser", "exampleIcon");
            dbContext.Add(category);
            dbContext.SaveChanges();

            var loggerMock = new Mock <ILogger <ConsumptionService> >();

            this.consumptionService = new ConsumptionService(loggerMock.Object, dbContext, GetMockHttpAccesor());
        }
예제 #2
0
        private void LoadPageData()
        {
            // for tests
            Car = CarService.FindById(1);

            Consumptions = ConsumptionService.Find(cons => cons.CarId == Car.Id).ToArray();
        }
        public SchemaMutation(ConsumptionService consumptionService, ConsumableService consumableService, MealService mealService)
        {
            Name = "Mutation";

            Field <ConsumptionType>("createConsumption", arguments: new QueryArguments(
                                        new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "consumableId"
            },
                                        new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "mealId"
            }),
                                    resolve: context => consumptionService.CreateAsync(context.GetArgument <int>(Name = "consumableId"),
                                                                                       context.GetArgument <int>(Name = "mealId")));

            Field <ConsumptionType>("removeConsumption", arguments: new QueryArguments(
                                        new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "consumptionId"
            }),
                                    resolve: context => consumptionService.RemoveAsync(context.GetArgument <int>(Name = "consumptionId")));

            Field <ConsumableType>("createConsumable", arguments: new QueryArguments(
                                       new QueryArgument <NonNullGraphType <ConsumableCreateInputType> > {
                Name = "consumable"
            }),
                                   resolve: context =>
                                   consumableService.CreateAsync(context.GetArgument <Consumable>(Name = "consumable")));

            Field <ConsumableType>("updateConsumable", arguments: new QueryArguments(
                                       new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "consumableId"
            },
                                       new QueryArgument <NonNullGraphType <ConsumableCreateInputType> > {
                Name = "consumable"
            }),
                                   resolve: context =>
                                   consumableService.UpdateAsync(context.GetArgument <int>(Name        = "consumableId"),
                                                                 context.GetArgument <Consumable>(Name = "consumable")));

            Field <ConsumableType>("removeConsumable", arguments: new QueryArguments(
                                       new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "consumableId"
            }),
                                   resolve: context =>
                                   consumableService.RemoveAsync(context.GetArgument <int>(Name = "consumableId")));

            Field <MealType>("createMeal", arguments: new QueryArguments(
                                 new QueryArgument <NonNullGraphType <MealCreateInputType> > {
                Name = "meal"
            }),
                             resolve: context => mealService.CreateAsync(context.GetArgument <Meal>(Name = "meal")));

            Field <MealType>("removeMeal",
                             arguments: new QueryArguments(new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "id"
            }),
                             resolve: context => mealService.RemoveAsync(context.GetArgument <int>(Name = "id"))
                             );
        }
예제 #4
0
 public BusinessLogicTests()
 {
     _db = new State();
     _db.Initialize();
     _incomingRepository           = new Repository <Incoming>(_db);
     _consumptionRepository        = new Repository <Consumption>(_db);
     _remainNomenclatureRepository = new RemainNomenclatureRegisterRepository(_db);
     _remainCostPrice           = new RemainCostPriceRegisterRepository(_db);
     _incomingService           = new IncomingService(_incomingRepository, _remainNomenclatureRepository, _remainCostPrice);
     _consumptionService        = new ConsumptionService(_consumptionRepository, _remainNomenclatureRepository, _remainCostPrice, _db);
     _remainNomenclatureBalance = new RemainNomenclatureBalanceRegisterRepository(_db);
     _remainCostPriceBalance    = new RemainCostPriceBalanceRegisterRepository(_db);
 }
예제 #5
0
        public SchemaQuery(ConsumptionService consumptionService, ConsumableService consumableService, MealService mealService)
        {
            Name = "Query";

            Field <ListGraphType <ConsumptionType> >("consumptions",
                                                     arguments: new QueryArguments(new QueryArgument <DateGraphType> {
                Name = "createdAt"
            }),
                                                     resolve: context => consumptionService.GetConsumptionsAsync(context.GetArgument <DateTime>("createdAt")));

            Field <ListGraphType <ConsumableType> >("consumables",
                                                    resolve: context => consumableService.GetConsumablesAsync());

            Field <ListGraphType <MealType> >("meals",
                                              resolve: context => mealService.GetMealsAsync());
        }
예제 #6
0
        public async Task  HandleValidSubmit()
        {
            var fullName = UserLogged.FindFirstValue("FullName");

            var userId = UserLogged.FindFirstValue(ClaimTypes.NameIdentifier);

            var consumption = new CarSharing.Repository.Models.Consumption
            {
                CurrentDate     = DateTime.Now,
                Distance        = Consumption.Distance,
                FuelConsumption = Consumption.FuelConsumption,
                Observations    = Consumption.Observations,
                UserName        = fullName,
                UserId          = Guid.Parse(userId),
                Car             = Car
            };

            await ConsumptionService.Add(consumption).ConfigureAwait(false);

            Consumption = new ConsumptionInputModel();

            LoadPageData();
        }
예제 #7
0
 public override void OnActionExecuting()
 {
     _consumptionService = CreateService <ConsumptionService>();
     _attachmentService  = CreateService <AttachmentService>();
 }