/// <summary>
        ///     Obtains an expenditure from the database.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <GetExpenditureResponse> GetExpenditure(GetExpenditureRequest request)
        {
            return(await Orchestrate(async delegate {
                var expenditure = await repository.GetExpenditure(request.ExpenditureId);

                return assembler.NewGetExpenditureResponse(expenditure, request.RequestReference);
            }, request));
        }
 public void TearDown()
 {
     orchestrator                     = null;
     assembler                        = null;
     dataAccess                       = null;
     validViewModel                   = null;
     validAddExpenditureRequest       = null;
     validAddExpenditureResponse      = null;
     invalidAddExpenditureRequest     = null;
     invalidAddExpenditureResponse    = null;
     validDeleteExpenditureRequest    = null;
     validDeleteExpenditureResponse   = null;
     invalidDeleteExpenditureRequest  = null;
     invalidDeleteExpenditureResponse = null;
     validGetExpenditureRequest       = null;
     validGetExpenditureResponse      = null;
     invalidGetExpenditureRequest     = null;
     invalidGetExpenditureResponse    = null;
     validExpenditureProxy            = null;
     invalidExpenditureViewModel      = null;
 }
        public void SetUp()
        {
            validViewModel = new ExpenditureViewModel
            {
                Amount   = 10,
                Category = "TEST",
                Id       = Guid.NewGuid(),
                UserId   = Guid.NewGuid()
            };

            validExpenditureProxy = new ExpenditureProxy
            {
                Amount   = 10,
                Category =
                    new CategoryProxy
                {
                    Id   = Guid.NewGuid(),
                    Name = "TEST"
                },
                CategoryId = Guid.NewGuid(),
                Id         = Guid.NewGuid(),
                UserId     = Guid.NewGuid()
            };

            validTrackExpenditureViewModel = new TrackExpenditureViewModel();

            validDeleteExpenditureRequest = new DeleteExpenditureRequest {
                ExpenditureId = validExpenditureProxy.Id
            };
            validDeleteExpenditureResponse = new DeleteExpenditureResponse {
                DeleteSuccess = true
            };
            validAddExpenditureRequest = new AddExpenditureRequest {
                Expenditure = validExpenditureProxy
            };
            validAddExpenditureResponse = new AddExpenditureResponse {
                Expenditure = validExpenditureProxy
            };
            validGetExpenditureRequest = new GetExpenditureRequest {
                ExpenditureId = validExpenditureProxy.Id
            };
            validGetExpenditureResponse = new GetExpenditureResponse {
                Expenditure = validExpenditureProxy
            };
            validGetExpenditureForUserRequest = new GetExpenditureForUserRequest {
                UserId = validExpenditureProxy.Id
            };
            validGetExpenditureForUserResponse =
                new GetExpenditureForUserResponse
            {
                Expenditure = new List <ExpenditureProxy> {
                    validExpenditureProxy
                }
            };
            validEditExpenditureRequest = new EditExpenditureRequest {
                Expenditure = validExpenditureProxy
            };
            validEditExpenditureResponse = new EditExpenditureResponse {
                Expenditure = validExpenditureProxy
            };
            validGetExpenditureForUserForMonthRequest =
                new GetExpenditureForUserForMonthRequest {
                UserId = validExpenditureProxy.Id
            };
            validGetExpenditureForUserForMonthResponse =
                new GetExpenditureForUserForMonthResponse
            {
                Data =
                    new List <ExpenditureProxy> {
                    validExpenditureProxy
                }
            };

            invalidExpenditureViewModel = new ExpenditureViewModel {
                Id = Guid.NewGuid()
            };
            invalidAddExpenditureRequest  = new AddExpenditureRequest();
            invalidAddExpenditureResponse = new AddExpenditureResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetExpenditureRequest  = new GetExpenditureRequest();
            invalidGetExpenditureResponse = new GetExpenditureResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidDeleteExpenditureRequest  = new DeleteExpenditureRequest();
            invalidDeleteExpenditureResponse =
                new DeleteExpenditureResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetExpenditureForUserRequest  = new GetExpenditureForUserRequest();
            invalidGetExpenditureForUserResponse =
                new GetExpenditureForUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidEditExpenditureRequest  = new EditExpenditureRequest();
            invalidEditExpenditureResponse = new EditExpenditureResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetExpenditureForUserForMonthRequest  = new GetExpenditureForUserForMonthRequest();
            invalidGetExpenditureForUserForMonthResponse =
                new GetExpenditureForUserForMonthResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            assembler   = Substitute.For <IExpenditureAssembler>();
            dataAccess  = Substitute.For <IExpenditureDataAccess>();
            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.NewAddExpenditureRequest(validViewModel, validUsername).Returns(validAddExpenditureRequest);
            assembler.NewAddExpenditureRequest(invalidExpenditureViewModel, validUsername)
            .Returns(invalidAddExpenditureRequest);
            assembler.NewAddExpenditureRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewExpenditureViewModel(validAddExpenditureResponse).Returns(validViewModel);
            assembler.NewExpenditureViewModel(validEditExpenditureResponse).Returns(validViewModel);
            assembler.NewDeleteExpenditureRequest(validViewModel.Id, validUsername)
            .Returns(validDeleteExpenditureRequest);
            assembler.NewDeleteExpenditureRequest(invalidExpenditureViewModel.Id, validUsername)
            .Returns(invalidDeleteExpenditureRequest);
            assembler.NewDeleteExpenditureRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetExpenditureRequest(validViewModel.Id, validUsername).Returns(validGetExpenditureRequest);
            assembler.NewGetExpenditureRequest(invalidExpenditureViewModel.Id, validUsername)
            .Returns(invalidGetExpenditureRequest);
            assembler.NewGetExpenditureRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetExpenditureForUserRequest(validViewModel.Id, validUsername)
            .Returns(validGetExpenditureForUserRequest);
            assembler.NewGetExpenditureForUserRequest(invalidExpenditureViewModel.Id, validUsername)
            .Returns(invalidGetExpenditureForUserRequest);
            assembler.NewGetExpenditureForUserRequest(Guid.Empty, validUsername)
            .Throws(new Exception("TEST EXCEPTION"));
            assembler.NewEditExpenditureRequest(validViewModel, validUsername).Returns(validEditExpenditureRequest);
            assembler.NewEditExpenditureRequest(invalidExpenditureViewModel, validUsername)
            .Returns(invalidEditExpenditureRequest);
            assembler.NewEditExpenditureRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetExpenditureForUserForMonthRequest(1, validViewModel.Id, validUsername)
            .Returns(validGetExpenditureForUserForMonthRequest);
            assembler.NewGetExpenditureForUserForMonthRequest(1, invalidExpenditureViewModel.Id, validUsername)
            .Returns(invalidGetExpenditureForUserForMonthRequest);
            assembler.NewTrackExpenditureViewModel(validGetExpenditureForUserResponse)
            .Returns(validTrackExpenditureViewModel);
            assembler.NewExportViewModel(Arg.Any <IList <ExpenditureProxy> >(), ExportType.Json)
            .Throws(new Exception("TEST"));

            dataAccess.AddExpenditure(validAddExpenditureRequest).Returns(validAddExpenditureResponse);
            dataAccess.AddExpenditure(invalidAddExpenditureRequest).Returns(invalidAddExpenditureResponse);
            dataAccess.DeleteExpenditure(validDeleteExpenditureRequest).Returns(validDeleteExpenditureResponse);
            dataAccess.DeleteExpenditure(invalidDeleteExpenditureRequest).Returns(invalidDeleteExpenditureResponse);
            dataAccess.GetExpenditure(validGetExpenditureRequest).Returns(validGetExpenditureResponse);
            dataAccess.GetExpenditure(invalidGetExpenditureRequest).Returns(invalidGetExpenditureResponse);
            dataAccess.GetExpenditureForUser(validGetExpenditureForUserRequest)
            .Returns(validGetExpenditureForUserResponse);
            dataAccess.GetExpenditureForUser(invalidGetExpenditureForUserRequest)
            .Returns(invalidGetExpenditureForUserResponse);
            dataAccess.EditExpenditure(validEditExpenditureRequest).Returns(validEditExpenditureResponse);
            dataAccess.EditExpenditure(invalidEditExpenditureRequest).Returns(invalidEditExpenditureResponse);
            dataAccess.GetExpenditureForUserForMonth(validGetExpenditureForUserForMonthRequest)
            .Returns(validGetExpenditureForUserForMonthResponse);
            dataAccess.GetExpenditureForUserForMonth(invalidGetExpenditureForUserForMonthRequest)
            .Returns(invalidGetExpenditureForUserForMonthResponse);

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

            orchestrator = new ExpenditureOrchestrator(assembler, dataAccess, errorHelper);
        }
        public void SetUp()
        {
            userId        = Guid.NewGuid();
            expenditureId = Guid.NewGuid();

            validData = new List <ExpenditureDataModel>();

            invalidDeleteExpenditureRequest             = new DeleteExpenditureRequest();
            invalidEditExpenditureRequest               = new EditExpenditureRequest();
            invalidGetExpenditureForUserForMonthRequest = new GetExpenditureForUserForMonthRequest();
            invalidGetExpenditureForUserRequest         = new GetExpenditureForUserRequest();
            invalidGetExpenditureRequest = new GetExpenditureRequest();
            invalidAddExpenditureRequest = new AddExpenditureRequest();

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

            expenditureProxy = new ExpenditureProxy
            {
                Amount   = 1.0,
                Category =
                    new CategoryProxy {
                    Id = Guid.NewGuid(), Name = "TEST"
                },
                CategoryId   = Guid.NewGuid(),
                DateOccurred = DateTime.Now,
                Description  = "TEST",
                Id           = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            validDeleteExpenditureRequest =
                new DeleteExpenditureRequest {
                ExpenditureId = Guid.NewGuid(), Username = "******"
            };

            validGetExpenditureForUserForMonthRequest =
                new GetExpenditureForUserForMonthRequest {
                MonthNumber = 1, UserId = userId, Username = "******"
            };

            validAddExpenditureRequest =
                new AddExpenditureRequest {
                Expenditure = expenditureProxy, Username = "******"
            };

            validGetExpenditureForUserRequest = new GetExpenditureForUserRequest {
                UserId = userId, Username = "******"
            };

            validGetExpenditureRequest = new GetExpenditureRequest {
                ExpenditureId = expenditureId, Username = "******"
            };

            validEditExpenditureRequest =
                new EditExpenditureRequest {
                Expenditure = expenditureProxy, Username = "******"
            };

            validGetExpenditureForUserResponse =
                new GetExpenditureForUserResponse {
                Expenditure = new List <ExpenditureProxy> {
                    expenditureProxy
                }
            };
            validGetExpenditureResponse = new GetExpenditureResponse {
                Expenditure = expenditureProxy
            };
            validAddExpenditureResponse = new AddExpenditureResponse {
                Expenditure = expenditureProxy
            };
            validEditExpenditureResponse = new EditExpenditureResponse {
                Expenditure = expenditureProxy
            };
            validDeleteExpenditureResponse = new DeleteExpenditureResponse {
                DeleteSuccess = true
            };
            validGetExpenditureForUserForMonthResponse =
                new GetExpenditureForUserForMonthResponse {
                Data = new List <ExpenditureProxy> {
                    expenditureProxy
                }
            };

            assembler  = Substitute.For <IExpenditureAssembler>();
            repository = Substitute.For <IExpenditureRepository>();

            repository.AddExpenditure(validExpenditureDataModel).Returns(validExpenditureDataModel);
            repository.AddExpenditure(null).Throws(new Exception("TEST"));

            repository.DeleteExpenditure(validDeleteExpenditureRequest.ExpenditureId).Returns(true);
            repository.DeleteExpenditure(invalidDeleteExpenditureRequest.ExpenditureId).Throws(new Exception("TEST"));

            repository.EditExpenditure(validExpenditureDataModel).Returns(validExpenditureDataModel);
            repository.EditExpenditure(null).Throws(new Exception("TEST"));

            repository.GetExpenditure(expenditureId).Returns(validExpenditureDataModel);
            repository.GetExpenditure(Guid.Empty).Throws(new Exception("TEST"));

            repository.GetExpenditureForUser(validGetExpenditureForUserRequest.UserId)
            .Returns(new List <ExpenditureDataModel> {
                validExpenditureDataModel
            });
            repository.GetExpenditureForUser(Guid.Empty).Throws(new Exception("TEST"));

            repository.GetExpenditureForUserForMonth(userId)
            .Returns(new List <ExpenditureDataModel> {
                validExpenditureDataModel
            });
            repository.GetExpenditureForUserForMonth(Guid.Empty).Throws(new Exception("TEST"));

            assembler.NewAddExpenditureResponse(validExpenditureDataModel, validAddExpenditureRequest.RequestReference)
            .Returns(validAddExpenditureResponse);

            assembler.NewDeleteExpenditureResponse(true, validDeleteExpenditureRequest.ExpenditureId)
            .Returns(validDeleteExpenditureResponse);

            assembler.NewEditExpenditureResponse(
                validExpenditureDataModel,
                validEditExpenditureRequest.RequestReference)
            .Returns(validEditExpenditureResponse);

            assembler.NewExpenditureDataModel(expenditureProxy).Returns(validExpenditureDataModel);

            assembler.NewGetExpenditureForUserForMonthResponse(
                Arg.Any <List <ExpenditureDataModel> >(),
                validGetExpenditureForUserForMonthRequest.RequestReference)
            .Returns(validGetExpenditureForUserForMonthResponse);

            assembler.NewGetExpenditureForUserResponse(
                Arg.Any <List <ExpenditureDataModel> >(),
                validGetExpenditureForUserRequest.RequestReference)
            .Returns(validGetExpenditureForUserResponse);

            assembler.NewDeleteExpenditureResponse(true, validDeleteExpenditureRequest.RequestReference)
            .Returns(validDeleteExpenditureResponse);

            assembler.NewGetExpenditureResponse(validExpenditureDataModel, validGetExpenditureRequest.RequestReference)
            .Returns(validGetExpenditureResponse);

            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 ExpenditureOrchestrator(repository, assembler, errorHelper);
        }
 /// <summary>
 ///     Sends an HTTP GET request to obtain a expenditure from the database.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>
 ///     The response object.
 /// </returns>
 public async Task <GetExpenditureResponse> GetExpenditure(GetExpenditureRequest request)
 {
     return(await Get <GetExpenditureResponse>(request.FormatRequestUri(), request.Username));
 }
示例#6
0
        public async Task <IHttpActionResult> GetExpenditure([FromUri] GetExpenditureRequest request)
        {
            var response = await orchestrator.GetExpenditure(request);

            return(Ok(response));
        }