Ejemplo n.º 1
0
        /// <summary>
        ///     Adds a bill.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <AddBillResponse> AddBill(AddBillRequest request)
        {
            return(await Orchestrate(async delegate {
                var dataModel = assembler.NewBillDataModel(request.Bill);
                var bill = await repository.AddBill(dataModel);

                return assembler.NewAddBillResponse(bill, request.RequestReference);
            }, request));
        }
Ejemplo n.º 2
0
        public Bill Add(int idUser, Bill bill)
        {
            var request = new AddBillRequest();

            request.idUser = idUser;
            request.Bill   = bill;

            var response = HttpPost <AddBillRequest>("api/Bill/Add", request, MediaType.Json);

            return(response.Bill);
        }
Ejemplo n.º 3
0
            public IEndpointHelperSetup AddBill(AddBillRequest request)
            {
                var requestBody = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");
                var result      = _fakeSever.PostAsync("/Api/v2/Bills", requestBody).Result;

                var             responseBody = result.Content.ReadAsStringAsync().Result;
                AddBillResponse billResponse = JsonConvert.DeserializeObject <AddBillResponse>(responseBody);

                _testBillsAdded.Add(billResponse.Id);
                return(this);
            }
Ejemplo n.º 4
0
        public AddBillResponse AddBill([FromBody] AddBillRequest billRequest)
        {
            var response = new AddBillResponse();

            try
            {
                if (_userService.AuthenticateSession(Request.Headers["Authorization"].ToString()) == false)
                {
                    response.AddError("The authorization credentails were invalid", ErrorCode.SESSION_INVALID);
                    return(response);
                }

                ActiveUser user = _userService.GetUserInformationFromAuthHeader(Request.Headers["Authorization"].ToString());
                if (user.HouseId == 0)
                {
                    response.AddError("You must belong to a household to add bills", ErrorCode.USER_NOT_IN_HOUSEHOLD);
                    return(response);
                }

                AddBill bill = new AddBill
                {
                    Name          = billRequest.Name,
                    Due           = billRequest.Due,
                    PeopleIds     = billRequest.PeopleIds,
                    RecurringType = billRequest.RecurringType,
                    TotalAmount   = billRequest.TotalAmount,
                    HouseId       = user.HouseId
                };
                BillValidator.CheckIfValidBill(bill);
                response.Id = _billRepository.AddBill(bill);

                if (user.HouseId == 1)
                {
                    _discordService.AddBillNotification(billRequest.Name, billRequest.Due, billRequest.TotalAmount);
                }

                response.Notifications = new List <string>
                {
                    $"The bill '{billRequest.Name}' has been added"
                };
            }
            catch (ErrorCodeException exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest, exception.Code);
            }
            catch (Exception exception)
            {
                response.AddError($"An unexpected exception occured: {exception}", billRequest);
            }

            return(response);
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddBill([FromBody] AddBillRequest addRequest)
        {
            var bill  = addRequest.ToBill();
            var added = await _billService.AddBillAsync(addRequest.ToBill());

            if (!added)
            {
                NotFound();
            }

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUri = baseUrl + "/" + ApiRoutes.Bills.GetBill.Replace("{billId}", bill.Id.ToString());

            return(Created(locationUri, bill.ToBillResponse()));
        }
Ejemplo n.º 6
0
            public IEndpointHelperSetup AddCompletedBill(string name = null)
            {
                AddBillRequest request = new AddBillRequest
                {
                    Name      = name ?? "DEVELOPMENT TESTING BILL",
                    Due       = DateTime.Now,
                    PeopleIds = new List <int> {
                        5
                    },
                    TotalAmount   = 0,
                    RecurringType = RecurringType.None
                };

                return(AddBill(request));
            }
Ejemplo n.º 7
0
            public IEndpointHelperSetup AddOverdueBill(string name = null, int daysInPast = 7)
            {
                AddBillRequest request = new AddBillRequest
                {
                    Name      = name ?? "DEVELOPMENT TESTING BILL",
                    Due       = DateTime.Now.AddDays(-daysInPast),
                    PeopleIds = new List <int> {
                        5
                    },
                    TotalAmount   = 299,
                    RecurringType = RecurringType.None
                };

                return(AddBill(request));
            }
Ejemplo n.º 8
0
 public static Bill ToBill(this AddBillRequest addRequest)
 {
     return(new Bill
     {
         Id = Guid.NewGuid(),
         Name = addRequest.Name,
         Occurance = addRequest.Occurance,
         Category = addRequest.Category,
         BillDate = addRequest.BillDate,
         DueDate = addRequest.DueDate,
         PeriodFrom = addRequest.PeriodFrom,
         PeriodTo = addRequest.PeriodTo,
         Price = addRequest.Price,
         IsPaid = addRequest.IsPaid,
         PaidDate = addRequest.PaidDate,
         Document = addRequest.Document
     });
 }
Ejemplo n.º 9
0
 public AddBillResponse Add(AddBillRequest request)
 {
     try
     {
         var response = new AddBillResponse();
         var bc       = new BillComponent();
         response.Result = bc.Add(request.idUser, request.Bill);
         return(response);
     }
     catch (Exception ex)
     {
         var httpError = new HttpResponseMessage()
         {
             StatusCode   = (HttpStatusCode)422, // UNPROCESSABLE ENTITY
             ReasonPhrase = ex.Message
         };
         throw new HttpResponseException(httpError);
     }
 }
 public void TearDown()
 {
     orchestrator              = null;
     assembler                 = null;
     dataAccess                = null;
     validViewModel            = null;
     validAddBillRequest       = null;
     validAddBillResponse      = null;
     invalidAddBillRequest     = null;
     invalidAddBillResponse    = null;
     validDeleteBillRequest    = null;
     validDeleteBillResponse   = null;
     invalidDeleteBillRequest  = null;
     invalidDeleteBillResponse = null;
     validGetBillRequest       = null;
     validGetBillResponse      = null;
     invalidGetBillRequest     = null;
     invalidGetBillResponse    = null;
     validBillProxy            = null;
     invalidBillViewModel      = null;
 }
Ejemplo n.º 11
0
 public override async Task<AddBillResponse> AddBill(AddBillRequest request, ServerCallContext context)
 {
     _logger.LogInformation("Usao u dodavanje racuna");
     await _context.Bills.ToListAsync();
     Bill bill = _convert.Convert(request.BillForRequest);
     try
     {
         _logger.LogInformation("usao u try");
         if (_context.Bills.Find(bill.barcode) is not null || bill.barcode==" ")
         {
             _logger.LogInformation("Nije Dodao Racun sa Barcodom" + bill.barcode + " jer postoji u bazi!");
             return new AddBillResponse { Success = false, Message = "Ovaj Barcode već postoji! " };
             
         }
         else
         {
             await _context.Bills.AddAsync(bill);
             await _context.SaveChangesAsync();
             _logger.LogInformation("Dodao Racun sa Barcodom" + bill.barcode);
             return new AddBillResponse { Success = true, Message = "Uspelo je upisivanje u bazu", BillForResponse = request.BillForRequest };
         }
         
     }
Ejemplo n.º 12
0
 /// <summary>
 ///     Sends an HTTP POST request to add a bill to the database.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>
 ///     The response object.
 /// </returns>
 public async Task <AddBillResponse> AddBill(AddBillRequest request)
 {
     return(await Post <AddBillResponse>(request));
 }
Ejemplo n.º 13
0
        public void SetUp()
        {
            userId        = Guid.NewGuid();
            expenditureId = Guid.NewGuid();

            validData = new List <BillDataModel>();

            invalidDeleteBillRequest = new DeleteBillRequest();
            invalidEditBillRequest   = new EditBillRequest();
            invalidGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest();
            invalidGetBillsForUserRequest         = new GetBillsForUserRequest();
            invalidGetBillRequest = new GetBillRequest();
            invalidAddBillRequest = new AddBillRequest();

            validBillDataModel =
                new BillDataModel
            {
                Amount   = 1,
                Category =
                    new CategoryDataModel
                {
                    CreationTime = DateTime.Now,
                    Id           = Guid.NewGuid(),
                    Name         = "TEST"
                },
                CreationTime = DateTime.Now,
                CategoryId   = Guid.NewGuid(),
                Id           = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            expenditureProxy = new BillProxy
            {
                Amount   = 1.0,
                Category =
                    new CategoryProxy {
                    Id = Guid.NewGuid(), Name = "TEST"
                },
                CategoryId = Guid.NewGuid(),
                Id         = Guid.NewGuid(),
                UserId     = Guid.NewGuid()
            };

            validDeleteBillRequest =
                new DeleteBillRequest {
                BillId = Guid.NewGuid(), Username = "******"
            };

            validGetBillsForUserForMonthRequest =
                new GetBillsForUserForMonthRequest {
                MonthNumber = 1, UserId = userId, Username = "******"
            };

            validAddBillRequest =
                new AddBillRequest {
                Bill = expenditureProxy, Username = "******"
            };

            validGetBillsForUserRequest = new GetBillsForUserRequest {
                UserId = userId, Username = "******"
            };

            validGetBillRequest = new GetBillRequest {
                BillId = expenditureId, Username = "******"
            };

            validEditBillRequest =
                new EditBillRequest {
                Bill = expenditureProxy, Username = "******"
            };

            validGetBillsForUserResponse =
                new GetBillsForUserResponse {
                Bills = new List <BillProxy> {
                    expenditureProxy
                }
            };
            validGetBillResponse = new GetBillResponse {
                Bill = expenditureProxy
            };
            validAddBillResponse = new AddBillResponse {
                Bill = expenditureProxy
            };
            validEditBillResponse = new EditBillResponse {
                Bill = expenditureProxy
            };
            validDeleteBillResponse = new DeleteBillResponse {
                DeleteSuccess = true
            };
            validGetBillsForUserForMonthResponse =
                new GetBillsForUserForMonthResponse {
                Data = new List <KeyValuePair <DateTime, double> > {
                    new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
                }
            };

            assembler       = Substitute.For <IBillAssembler>();
            repository      = Substitute.For <IBillRepository>();
            dataTransformer = Substitute.For <IBillDataTransformer>();

            repository.AddBill(validBillDataModel).Returns(validBillDataModel);
            repository.AddBill(null).Throws(new Exception("TEST"));

            repository.DeleteBill(validDeleteBillRequest.BillId).Returns(true);
            repository.DeleteBill(invalidDeleteBillRequest.BillId).Throws(new Exception("TEST"));

            repository.EditBill(validBillDataModel).Returns(validBillDataModel);
            repository.EditBill(null).Throws(new Exception("TEST"));

            repository.GetBill(expenditureId).Returns(validBillDataModel);
            repository.GetBill(Guid.Empty).Throws(new Exception("TEST"));

            repository.GetBillsForUser(validGetBillsForUserRequest.UserId)
            .Returns(new List <BillDataModel> {
                validBillDataModel
            });
            repository.GetBillsForUser(Guid.Empty).Throws(new Exception("TEST"));

            dataTransformer.GetOutgoingBillsForMonth(Arg.Any <int>(), Arg.Any <List <BillDataModel> >())
            .Returns(
                new List <KeyValuePair <DateTime, double> > {
                new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
            });

            dataTransformer.GetBillCategoryChartData(Arg.Any <List <BillDataModel> >())
            .Returns(new List <KeyValuePair <string, int> > {
                new KeyValuePair <string, int>()
            });

            assembler.NewAddBillResponse(validBillDataModel, validAddBillRequest.RequestReference)
            .Returns(validAddBillResponse);

            assembler.NewDeleteBillResponse(true, validDeleteBillRequest.BillId)
            .Returns(validDeleteBillResponse);

            assembler.NewEditBillResponse(
                validBillDataModel,
                validEditBillRequest.RequestReference)
            .Returns(validEditBillResponse);

            assembler.NewBillDataModel(expenditureProxy).Returns(validBillDataModel);

            assembler.NewGetBillsForUserForMonthResponse(
                Arg.Any <List <KeyValuePair <DateTime, double> > >(),
                validGetBillsForUserForMonthRequest.RequestReference)
            .Returns(validGetBillsForUserForMonthResponse);

            assembler.NewGetBillsForUserResponse(
                Arg.Any <List <BillDataModel> >(),
                validGetBillsForUserRequest.RequestReference)
            .Returns(validGetBillsForUserResponse);

            assembler.NewDeleteBillResponse(true, validDeleteBillRequest.RequestReference)
            .Returns(validDeleteBillResponse);

            assembler.NewGetBillResponse(validBillDataModel, validGetBillRequest.RequestReference)
            .Returns(validGetBillResponse);

            errorHelper = Substitute.For <IErrorHelper>();

            errorHelper.Create(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());
            errorHelper.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());

            orchestrator = new BillOrchestrator(assembler, repository, dataTransformer, errorHelper);
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> AddBill([FromBody] AddBillRequest request)
        {
            await billsModule.ExecuteCommandAsync(new AddBill(request.Date, request.StoreId, request.Purchases));

            return(Ok());
        }
Ejemplo n.º 15
0
        public async Task <IHttpActionResult> AddBill([FromBody] AddBillRequest request)
        {
            var response = await orchestrator.AddBill(request);

            return(Ok(response));
        }
        public void SetUp()
        {
            validViewModel = new BillViewModel
            {
                Amount            = 10,
                Category          = "TEST",
                Id                = Guid.NewGuid(),
                Name              = "TEST",
                ReoccurringPeriod = TimePeriod.Daily,
                StartDate         = DateTime.Now,
                UserId            = Guid.NewGuid()
            };

            validBillProxy = new BillProxy
            {
                Amount   = 10,
                Category = new CategoryProxy {
                    Id = Guid.NewGuid(), Name = "TEST"
                },
                CategoryId        = Guid.NewGuid(),
                Id                = Guid.NewGuid(),
                Name              = "TEST",
                ReoccurringPeriod = 1,
                StartDate         = DateTime.Now,
                UserId            = Guid.NewGuid()
            };

            validManageBillsViewModel = new ManageBillsViewModel();

            validDeleteBillRequest = new DeleteBillRequest {
                BillId = validBillProxy.Id
            };
            validDeleteBillResponse = new DeleteBillResponse {
                DeleteSuccess = true
            };
            validAddBillRequest = new AddBillRequest {
                Bill = validBillProxy
            };
            validAddBillResponse = new AddBillResponse {
                Bill = validBillProxy
            };
            validGetBillRequest = new GetBillRequest {
                BillId = validBillProxy.Id
            };
            validGetBillResponse = new GetBillResponse {
                Bill = validBillProxy
            };
            validGetBillsForUserRequest = new GetBillsForUserRequest {
                UserId = validBillProxy.Id
            };
            validGetBillsForUserResponse =
                new GetBillsForUserResponse {
                Bills = new List <BillProxy> {
                    validBillProxy
                }
            };
            validEditBillRequest = new EditBillRequest {
                Bill = validBillProxy
            };
            validEditBillResponse = new EditBillResponse {
                Bill = validBillProxy
            };
            validGetBillsForUserForMonthRequest = new GetBillsForUserForMonthRequest {
                UserId = validBillProxy.Id
            };
            validGetBillsForUserForMonthResponse =
                new GetBillsForUserForMonthResponse {
                Data = new List <KeyValuePair <DateTime, double> >()
            };

            invalidBillViewModel = new BillViewModel {
                Id = Guid.NewGuid()
            };
            invalidAddBillRequest  = new AddBillRequest();
            invalidAddBillResponse = new AddBillResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetBillRequest  = new GetBillRequest();
            invalidGetBillResponse = new GetBillResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidDeleteBillRequest  = new DeleteBillRequest();
            invalidDeleteBillResponse = new DeleteBillResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetBillsForUserRequest  = new GetBillsForUserRequest();
            invalidGetBillsForUserResponse = new GetBillsForUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidEditBillRequest  = new EditBillRequest();
            invalidEditBillResponse = new EditBillResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetBillsForUserForMonthRequest  = new GetBillsForUserForMonthRequest();
            invalidGetBillsForUserForMonthResponse =
                new GetBillsForUserForMonthResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            assembler   = Substitute.For <IBillAssembler>();
            dataAccess  = Substitute.For <IBillDataAccess>();
            errorHelper = Substitute.For <IErrorHelper>();

            errorHelper.Create(Arg.Any <Exception>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());
            errorHelper.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <Type>(), Arg.Any <string>())
            .Returns(new ResponseErrorWrapper());

            assembler.NewAddBillRequest(validViewModel, validUsername).Returns(validAddBillRequest);
            assembler.NewAddBillRequest(invalidBillViewModel, validUsername).Returns(invalidAddBillRequest);
            assembler.NewAddBillRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewBillViewModel(validAddBillResponse).Returns(validViewModel);
            assembler.NewBillViewModel(validEditBillResponse).Returns(validViewModel);
            assembler.NewDeleteBillRequest(validViewModel.Id, validUsername).Returns(validDeleteBillRequest);
            assembler.NewDeleteBillRequest(invalidBillViewModel.Id, validUsername).Returns(invalidDeleteBillRequest);
            assembler.NewDeleteBillRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetBillRequest(validViewModel.Id, validUsername).Returns(validGetBillRequest);
            assembler.NewGetBillRequest(invalidBillViewModel.Id, validUsername).Returns(invalidGetBillRequest);
            assembler.NewGetBillRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetBillsForUserRequest(validViewModel.Id, validUsername).Returns(validGetBillsForUserRequest);
            assembler.NewGetBillsForUserRequest(invalidBillViewModel.Id, validUsername)
            .Returns(invalidGetBillsForUserRequest);
            assembler.NewGetBillsForUserRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewEditBillRequest(validViewModel, validUsername).Returns(validEditBillRequest);
            assembler.NewEditBillRequest(invalidBillViewModel, validUsername).Returns(invalidEditBillRequest);
            assembler.NewEditBillRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetBillsForUserForMonthRequest(1, validViewModel.Id, validUsername)
            .Returns(validGetBillsForUserForMonthRequest);
            assembler.NewGetBillsForUserForMonthRequest(1, invalidBillViewModel.Id, validUsername)
            .Returns(invalidGetBillsForUserForMonthRequest);
            assembler.NewManageBillsViewModel(validGetBillsForUserResponse).Returns(validManageBillsViewModel);
            assembler.NewExportViewModel(ExportType.Json, Arg.Any <IList <BillProxy> >()).Throws(new Exception("TEST"));

            dataAccess.AddBill(validAddBillRequest).Returns(validAddBillResponse);
            dataAccess.AddBill(invalidAddBillRequest).Returns(invalidAddBillResponse);
            dataAccess.DeleteBill(validDeleteBillRequest).Returns(validDeleteBillResponse);
            dataAccess.DeleteBill(invalidDeleteBillRequest).Returns(invalidDeleteBillResponse);
            dataAccess.GetBill(validGetBillRequest).Returns(validGetBillResponse);
            dataAccess.GetBill(invalidGetBillRequest).Returns(invalidGetBillResponse);
            dataAccess.GetBillsForUser(validGetBillsForUserRequest).Returns(validGetBillsForUserResponse);
            dataAccess.GetBillsForUser(invalidGetBillsForUserRequest).Returns(invalidGetBillsForUserResponse);
            dataAccess.EditBill(validEditBillRequest).Returns(validEditBillResponse);
            dataAccess.EditBill(invalidEditBillRequest).Returns(invalidEditBillResponse);
            dataAccess.GetBillsForUserForMonth(validGetBillsForUserForMonthRequest)
            .Returns(validGetBillsForUserForMonthResponse);
            dataAccess.GetBillsForUserForMonth(invalidGetBillsForUserForMonthRequest)
            .Returns(invalidGetBillsForUserForMonthResponse);

            assembler.NewExportViewModel(ExportType.Csv, new List <BillProxy> {
                validBillProxy
            })
            .Returns(new ExportViewModel());

            orchestrator = new BillOrchestrator(assembler, dataAccess, errorHelper);
        }