/// <summary>
        ///     Builds and sends an HTTP request for the data required to produce the bill category chart.
        /// </summary>
        /// <param name="userId">The user identifier.</param>
        /// <param name="username">The username.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <OrchestratorResponseWrapper <IList <KeyValuePair <string, int> > > > GetBillCategoryChartData(
            Guid userId,
            string username)
        {
            var response = new OrchestratorResponseWrapper <IList <KeyValuePair <string, int> > >();

            try
            {
                var request     = assembler.NewGetBillCategoryChartDataRequest(userId, username);
                var apiResponse = await dataAccess.GetBillCategoryChartData(request);

                if (!apiResponse.Success)
                {
                    response.AddErrors(apiResponse.Errors);
                    return(response);
                }

                response.Model = apiResponse.Data;
            }
            catch (Exception ex)
            {
                var err = errorHelper.Create(ex, username, GetType(), "GetBillCategoryChartData");
                response.AddError(err);
            }

            return(response);
        }
        /// <summary>
        ///     Adds a goal to the database.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="username">The username.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <OrchestratorResponseWrapper <GoalViewModel> > AddGoal(GoalViewModel model, string username)
        {
            var response = new OrchestratorResponseWrapper <GoalViewModel>();

            try
            {
                var request     = assembler.NewAddGoalRequest(model, username);
                var apiResponse = await dataAccess.AddGoal(request);

                if (!apiResponse.Success)
                {
                    response.AddErrors(apiResponse.Errors);
                }
                else
                {
                    response.Model = assembler.ProxyToViewModel(apiResponse.Goal);
                }

                response.AddWarnings(apiResponse.Warnings);
            }
            catch (Exception ex)
            {
                var err = errorHelper.Create(ex, username, GetType(), "AddGoal");
                response.AddError(err);
            }

            return(response);
        }
Example #3
0
        /// <summary>
        ///     Handles the Error event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void Application_Error(object sender, EventArgs e)
        {
            var error = Server.GetLastError();

            var userId = ((ClaimsIdentity)User.Identity).Claims
                         .FirstOrDefault(c => c.Type.Equals(ClaimTypes.Email))
                         ?.Value;

            errorHelper.Create(error, userId, GetType(), "Application_Error");

            HttpContext.Current.Response.RedirectToRoute(
                new { action = "SystemError", controller = "Error", area = "Common" });
        }
Example #4
0
        /// <summary>
        ///     Sends an HTTP DELETE request to the given uri.
        /// </summary>
        /// <typeparam name="T">The response type.</typeparam>
        /// <param name="uri">The URI.</param>
        /// <param name="username">The username.</param>
        /// <returns>The response object.</returns>
        protected async Task <T> Delete <T>(string uri, string username)
            where T : BaseResponse
        {
            var response = (T)Activator.CreateInstance(typeof(T));

            HttpResponseMessage httpResponse;

            using (benchmarkHelper.Create(uri))
            {
                httpResponse = await client.DeleteAsync(uri);
            }

            if (!httpResponse.IsSuccessStatusCode)
            {
                var err = errorHelper.Create(GetHttpError(httpResponse), username, GetType(), "Delete");
                response.AddError(err);

                return(response);
            }

            response = await httpResponse.Content.ReadAsAsync <T>();

            return(response);
        }
        /// <summary>
        ///     Adds model state errors to the JSON response.
        /// </summary>
        /// <param name="state">The model state.</param>
        /// <returns>The <see cref="ContentResult" />.</returns>
        protected ContentResult InvalidModelState(ModelStateDictionary state)
        {
            var response = new OrchestratorResponseWrapper <bool>();

            foreach (var modelState in state.Values)
            {
                foreach (var error in modelState.Errors)
                {
                    var errorWrapper = errorHelper.Create(
                        error.ErrorMessage,
                        UserEmail,
                        GetType(),
                        "InvalidModelState");

                    response.AddError(errorWrapper);
                }
            }

            return(JsonResponse(response));
        }
        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()
        {
            errorHelper                = Substitute.For <IErrorHelper>();
            assembler                  = Substitute.For <IChartAssembler>();
            billRepository             = Substitute.For <IBillRepository>();
            billDataTransformer        = Substitute.For <IBillDataTransformer>();
            expenditureRepository      = Substitute.For <IExpenditureRepository>();
            expenditureDataTransformer = Substitute.For <IExpenditureDataTransformer>();

            validGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest
            {
                UserId   = Guid.NewGuid(),
                Username = "******"
            };

            validGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest
            {
                UserId   = Guid.NewGuid(),
                Username = "******"
            };

            validGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = Guid.NewGuid(), Username = "******"
            };

            validBills       = new List <BillDataModel>();
            validExpenditure = new List <ExpenditureDataModel>();

            invalidGetBillPeriodChartDataRequest   = new GetBillPeriodChartDataRequest();
            invalidGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest();
            invalidGetExpenditureChartDataRequest  = new GetExpenditureChartDataRequest();

            billRepository.GetBillsForUser(validGetBillCategoryChartDataRequest.UserId).Returns(validBills);
            billRepository.GetBillsForUser(validGetBillPeriodChartDataRequest.UserId).Returns(validBills);
            billRepository.GetBillsForUser(Guid.Empty).Throws(new Exception("TEST"));

            expenditureRepository.GetExpenditureForUserForMonth(validGetExpenditureChartDataRequest.UserId)
            .Returns(validExpenditure);
            expenditureRepository.GetExpenditureForUserForMonth(Guid.Empty).Throws(new Exception("TEST"));

            validData = new List <KeyValuePair <string, int> > {
                new KeyValuePair <string, int>("TEST", 1)
            };

            billDataTransformer.GetBillCategoryChartData(validBills).Returns(validData);
            billDataTransformer.GetBillPeriodChartData(validBills).Returns(validData);

            expenditureDataTransformer.GetRollingExpenditureSum(validExpenditure)
            .Returns(
                new List <KeyValuePair <DateTime, double> >
            {
                new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
            });

            validGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse {
                Data = validData
            };
            validGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse {
                Data = validData
            };
            validGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse
            {
                Data = new List <KeyValuePair <DateTime, double> >
                {
                    new KeyValuePair <DateTime, double>(DateTime.Now, 1.0)
                }
            };

            assembler.NewGetExpenditureChartDataResponse(Arg.Any <IList <KeyValuePair <DateTime, double> > >(), Arg.Any <Guid>()).Returns(validGetExpenditureChartDataResponse);
            assembler.NewGetBillCategoryChartDataResponse(validData, Arg.Any <Guid>()).Returns(validGetBillCategoryChartDataResponse);
            assembler.NewGetBillPeriodChartDataResponse(validData, Arg.Any <Guid>()).Returns(validGetBillPeriodChartDataResponse);

            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 ChartOrchestrator(
                assembler,
                billRepository,
                billDataTransformer,
                expenditureRepository,
                expenditureDataTransformer,
                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);
        }
Example #9
0
        public void SetUp()
        {
            validRegisterUserRequest =
                new RegisterUserRequest
            {
                DateOfBirth  = DateTime.Today,
                EmailAddress = "TEST",
                FirstName    = "TEST",
                LastName     = "TEST",
                Password     = "******",
                Username     = "******"
            };

            validDataModel = new UserDataModel
            {
                Id           = Guid.NewGuid(),
                CreationTime = DateTime.Now,
                DateOfBirth  = DateTime.Today,
                EmailAddress = "TEST",
                FirstName    = "TEST",
                Hash         = new byte[] { },
                Iterations   = 1,
                LastName     = "TEST",
                Salt         = new byte[] { }
            };

            validRegisterUserResponse =
                new RegisterUserResponse
            {
                RegisterSuccess  = true,
                RequestReference = validRegisterUserRequest.RequestReference
            };

            invalidDataModel            = new UserDataModel();
            invalidRegisterUserRequest  = new RegisterUserRequest();
            invalidRegisterUserResponse = new RegisterUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            exceptionRegisterUserRequest = new RegisterUserRequest {
                DateOfBirth = DateTime.MinValue
            };

            validValidateUserRequest =
                new ValidateUserRequest {
                EmailAddress = "TEST", Password = "******", Username = "******"
            };
            invalidValidateUserRequest   = new ValidateUserRequest();
            exceptionValidateUserRequest = new ValidateUserRequest {
                EmailAddress = "EXC", Password = "******", Username = "******"
            };

            invalidValidateUserResponse = new ValidateUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            validValidateUserResponse = new ValidateUserResponse {
                LoginSuccess = true
            };

            assembler  = Substitute.For <IUserAssembler>();
            repository = Substitute.For <IUserRepository>();

            assembler.NewUserDataModel(validRegisterUserRequest).Returns(validDataModel);
            assembler.NewUserDataModel(invalidRegisterUserRequest).Returns(invalidDataModel);
            assembler.NewRegisterUserResponse(validDataModel, validRegisterUserRequest.RequestReference)
            .Returns(validRegisterUserResponse);
            assembler.NewUserDataModel(exceptionRegisterUserRequest).Throws(new Exception("TEST"));
            assembler.NewRegisterUserResponse(invalidDataModel, invalidRegisterUserRequest.RequestReference)
            .Returns(invalidRegisterUserResponse);
            assembler.NewValidateUserResponse(validDataModel, validValidateUserRequest.RequestReference)
            .Returns(validValidateUserResponse);
            assembler.NewValidateUserResponse(invalidDataModel, invalidValidateUserRequest.RequestReference)
            .Returns(invalidValidateUserResponse);


            repository.RegisterUser(validDataModel).Returns(validDataModel);
            repository.RegisterUser(invalidDataModel).Returns(invalidDataModel);
            repository.GetUser(validValidateUserRequest.EmailAddress, validValidateUserRequest.Password)
            .Returns(validDataModel);
            repository.GetUser(invalidValidateUserRequest.EmailAddress, invalidRegisterUserRequest.Password)
            .Returns(invalidDataModel);
            repository.GetUser(exceptionValidateUserRequest.EmailAddress, exceptionValidateUserRequest.Password)
            .Throws(new Exception("TEST"));

            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 UserOrchestrator(assembler, repository, errorHelper);
        }
Example #10
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);
        }
Example #11
0
        public void SetUp()
        {
            userId        = Guid.NewGuid();
            expenditureId = Guid.NewGuid();

            validData = new List <GoalDataModel>();

            invalidDeleteGoalRequest      = new DeleteGoalRequest();
            invalidEditGoalRequest        = new EditGoalRequest();
            invalidGetGoalsForUserRequest = new GetGoalsForUserRequest();
            invalidGetGoalRequest         = new GetGoalRequest();
            invalidAddGoalRequest         = new AddGoalRequest();

            validGoalDataModel = new GoalDataModel
            {
                Amount       = 1,
                CreationTime = DateTime.Now,
                Id           = Guid.NewGuid(),
                UserId       = Guid.NewGuid()
            };

            expenditureProxy = new GoalProxy {
                Amount = 1.0, Id = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            validDeleteGoalRequest = new DeleteGoalRequest {
                GoalId = Guid.NewGuid(), Username = "******"
            };

            validAddGoalRequest = new AddGoalRequest {
                Goal = expenditureProxy, Username = "******"
            };

            validGetGoalsForUserRequest = new GetGoalsForUserRequest {
                UserId = userId, Username = "******"
            };

            validGetGoalRequest = new GetGoalRequest {
                GoalId = expenditureId, Username = "******"
            };

            validEditGoalRequest = new EditGoalRequest {
                Goal = expenditureProxy, Username = "******"
            };

            validGetGoalsForUserResponse =
                new GetGoalsForUserResponse {
                Goals = new List <GoalProxy> {
                    expenditureProxy
                }
            };
            validGetGoalResponse = new GetGoalResponse {
                Goal = expenditureProxy
            };
            validAddGoalResponse = new AddGoalResponse {
                Goal = expenditureProxy
            };
            validEditGoalResponse = new EditGoalResponse {
                Goal = expenditureProxy
            };
            validDeleteGoalResponse = new DeleteGoalResponse {
                DeleteSuccess = true
            };

            assembler   = Substitute.For <IGoalAssembler>();
            repository  = Substitute.For <IGoalRepository>();
            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());

            repository.AddGoal(validGoalDataModel).Returns(validGoalDataModel);
            repository.AddGoal(null).Throws(new Exception("TEST"));

            repository.DeleteGoal(validDeleteGoalRequest.GoalId).Returns(true);
            repository.DeleteGoal(invalidDeleteGoalRequest.GoalId).Throws(new Exception("TEST"));

            repository.EditGoal(validGoalDataModel).Returns(validGoalDataModel);
            repository.EditGoal(null).Throws(new Exception("TEST"));

            repository.GetGoal(expenditureId).Returns(validGoalDataModel);
            repository.GetGoal(Guid.Empty).Throws(new Exception("TEST"));

            repository.GetGoalsForUser(validGetGoalsForUserRequest.UserId)
            .Returns(new List <GoalDataModel> {
                validGoalDataModel
            });
            repository.GetGoalsForUser(Guid.Empty).Throws(new Exception("TEST"));

            assembler.NewAddGoalResponse(validGoalDataModel, validAddGoalRequest.RequestReference)
            .Returns(validAddGoalResponse);

            assembler.NewDeleteGoalResponse(true, validDeleteGoalRequest.GoalId).Returns(validDeleteGoalResponse);

            assembler.NewEditGoalResponse(validGoalDataModel, validEditGoalRequest.RequestReference)
            .Returns(validEditGoalResponse);

            assembler.NewGoalDataModel(expenditureProxy).Returns(validGoalDataModel);

            assembler.NewGetGoalsForUserResponse(
                Arg.Any <List <GoalDataModel> >(),
                validGetGoalsForUserRequest.RequestReference)
            .Returns(validGetGoalsForUserResponse);

            assembler.NewDeleteGoalResponse(true, validDeleteGoalRequest.RequestReference)
            .Returns(validDeleteGoalResponse);

            assembler.NewGetGoalResponse(validGoalDataModel, validGetGoalRequest.RequestReference)
            .Returns(validGetGoalResponse);

            orchestrator = new GoalOrchestrator(assembler, repository, errorHelper);
        }
        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);
        }
Example #13
0
        public void SetUp()
        {
            assembler     = Substitute.For <IChartAssembler>();
            dataAccess    = Substitute.For <IChartDataAccess>();
            validUserId   = Guid.NewGuid();
            invalidUserId = Guid.Empty;
            validUsername = "******";

            validGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest
            {
                UserId   = validUserId,
                Username = validUsername
            };

            invalidGetBillCategoryChartDataRequest = new GetBillCategoryChartDataRequest();

            validGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse
            {
                Data =
                    new List
                    <
                        KeyValuePair <string, int> >()
            };

            invalidGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };

            validGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest
            {
                UserId   = validUserId,
                Username = validUsername
            };

            invalidGetBillPeriodChartDataRequest = new GetBillPeriodChartDataRequest();

            validGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Data =
                    new List
                    <
                        KeyValuePair <string, int> >()
            };

            invalidGetBillPeriodChartDataResponse = new GetBillPeriodChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };
            invalidGetBillCategoryChartDataResponse = new GetBillCategoryChartDataResponse
            {
                Errors =
                {
                    new ResponseErrorWrapper
                        ()
                }
            };

            validGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = validUserId, Username = validUsername
            };

            invalidGetExpenditureChartDataRequest =
                new GetExpenditureChartDataRequest {
                Month = 1, UserId = invalidUserId, Username = string.Empty
            };

            validGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse {
                Data = new List <KeyValuePair <DateTime, double> >()
            };

            invalidGetExpenditureChartDataResponse =
                new GetExpenditureChartDataResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            assembler.NewGetBillCategoryChartDataRequest(invalidUserId, validUsername)
            .Returns(invalidGetBillCategoryChartDataRequest);
            assembler.NewGetBillCategoryChartDataRequest(validUserId, validUsername)
            .Returns(validGetBillCategoryChartDataRequest);
            assembler.NewGetBillCategoryChartDataRequest(validUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));

            dataAccess.GetBillCategoryChartData(validGetBillCategoryChartDataRequest)
            .Returns(validGetBillCategoryChartDataResponse);
            dataAccess.GetBillCategoryChartData(invalidGetBillCategoryChartDataRequest)
            .Returns(invalidGetBillCategoryChartDataResponse);

            assembler.NewGetBillPeriodChartDataRequest(invalidUserId, validUsername)
            .Returns(invalidGetBillPeriodChartDataRequest);
            assembler.NewGetBillPeriodChartDataRequest(validUserId, validUsername)
            .Returns(validGetBillPeriodChartDataRequest);
            assembler.NewGetBillPeriodChartDataRequest(validUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));


            assembler.NewGetExpenditureChartDataRequest(1, invalidUserId, validUsername)
            .Returns(invalidGetExpenditureChartDataRequest);
            assembler.NewGetExpenditureChartDataRequest(1, validUserId, validUsername)
            .Returns(validGetExpenditureChartDataRequest);
            assembler.NewGetExpenditureChartDataRequest(-1, invalidUserId, string.Empty)
            .Throws(new Exception("TEST EXCEPTION"));

            dataAccess.GetBillPeriodChartData(validGetBillPeriodChartDataRequest)
            .Returns(validGetBillPeriodChartDataResponse);
            dataAccess.GetBillPeriodChartData(invalidGetBillPeriodChartDataRequest)
            .Returns(invalidGetBillPeriodChartDataResponse);

            dataAccess.GetExpenditureChartData(validGetExpenditureChartDataRequest)
            .Returns(validGetExpenditureChartDataResponse);
            dataAccess.GetExpenditureChartData(invalidGetExpenditureChartDataRequest)
            .Returns(invalidGetExpenditureChartDataResponse);

            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 ChartOrchestrator(assembler, dataAccess, errorHelper);
        }
Example #14
0
        public void SetUp()
        {
            validViewModel = new GoalViewModel {
                Amount = 10, Id = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            validGoalProxy = new GoalProxy {
                Amount = 10, Id = Guid.NewGuid(), UserId = Guid.NewGuid()
            };

            validManageGoalsViewModel = new ManageGoalsViewModel();

            validDeleteGoalRequest = new DeleteGoalRequest {
                GoalId = validGoalProxy.Id
            };
            validDeleteGoalResponse = new DeleteGoalResponse {
                DeleteSuccess = true
            };
            validAddGoalRequest = new AddGoalRequest {
                Goal = validGoalProxy
            };
            validAddGoalResponse = new AddGoalResponse {
                Goal = validGoalProxy
            };
            validGetGoalRequest = new GetGoalRequest {
                GoalId = validGoalProxy.Id
            };
            validGetGoalResponse = new GetGoalResponse {
                Goal = validGoalProxy
            };
            validGetGoalsForUserRequest = new GetGoalsForUserRequest {
                UserId = validGoalProxy.Id
            };
            validGetGoalsForUserResponse =
                new GetGoalsForUserResponse {
                Goals = new List <GoalProxy> {
                    validGoalProxy
                }
            };
            validEditGoalRequest = new EditGoalRequest {
                Goal = validGoalProxy
            };
            validEditGoalResponse = new EditGoalResponse {
                Goal = validGoalProxy
            };

            invalidGoalViewModel = new GoalViewModel {
                Id = Guid.NewGuid()
            };
            invalidAddGoalRequest  = new AddGoalRequest();
            invalidAddGoalResponse = new AddGoalResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetGoalRequest  = new GetGoalRequest();
            invalidGetGoalResponse = new GetGoalResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidDeleteGoalRequest  = new DeleteGoalRequest();
            invalidDeleteGoalResponse = new DeleteGoalResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidGetGoalsForUserRequest  = new GetGoalsForUserRequest();
            invalidGetGoalsForUserResponse = new GetGoalsForUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };
            invalidEditGoalRequest  = new EditGoalRequest();
            invalidEditGoalResponse = new EditGoalResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            assembler  = Substitute.For <IGoalAssembler>();
            dataAccess = Substitute.For <IGoalDataAccess>();

            assembler.NewAddGoalRequest(validViewModel, validUsername).Returns(validAddGoalRequest);
            assembler.NewAddGoalRequest(invalidGoalViewModel, validUsername).Returns(invalidAddGoalRequest);
            assembler.NewAddGoalRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewDeleteGoalRequest(validViewModel.Id, validUsername).Returns(validDeleteGoalRequest);
            assembler.NewDeleteGoalRequest(invalidGoalViewModel.Id, validUsername).Returns(invalidDeleteGoalRequest);
            assembler.NewDeleteGoalRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetGoalRequest(validViewModel.Id, validUsername).Returns(validGetGoalRequest);
            assembler.NewGetGoalRequest(invalidGoalViewModel.Id, validUsername).Returns(invalidGetGoalRequest);
            assembler.NewGetGoalRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewGetGoalsForUserRequest(validViewModel.Id, validUsername).Returns(validGetGoalsForUserRequest);
            assembler.NewGetGoalsForUserRequest(invalidGoalViewModel.Id, validUsername)
            .Returns(invalidGetGoalsForUserRequest);
            assembler.NewGetGoalsForUserRequest(Guid.Empty, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewEditGoalRequest(validViewModel, validUsername).Returns(validEditGoalRequest);
            assembler.NewEditGoalRequest(invalidGoalViewModel, validUsername).Returns(invalidEditGoalRequest);
            assembler.NewEditGoalRequest(null, validUsername).Throws(new Exception("TEST EXCEPTION"));
            assembler.NewManageGoalsViewModel(new List <GoalProxy> {
                validGoalProxy
            })
            .Returns(validManageGoalsViewModel);

            dataAccess.AddGoal(validAddGoalRequest).Returns(validAddGoalResponse);
            dataAccess.AddGoal(invalidAddGoalRequest).Returns(invalidAddGoalResponse);
            dataAccess.DeleteGoal(validDeleteGoalRequest).Returns(validDeleteGoalResponse);
            dataAccess.DeleteGoal(invalidDeleteGoalRequest).Returns(invalidDeleteGoalResponse);
            dataAccess.GetGoal(validGetGoalRequest).Returns(validGetGoalResponse);
            dataAccess.GetGoal(invalidGetGoalRequest).Returns(invalidGetGoalResponse);
            dataAccess.GetGoalsForUser(validGetGoalsForUserRequest).Returns(validGetGoalsForUserResponse);
            dataAccess.GetGoalsForUser(invalidGetGoalsForUserRequest).Returns(invalidGetGoalsForUserResponse);
            dataAccess.EditGoal(validEditGoalRequest).Returns(validEditGoalResponse);
            dataAccess.EditGoal(invalidEditGoalRequest).Returns(invalidEditGoalResponse);

            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 GoalOrchestrator(dataAccess, assembler, errorHelper);
        }
        public void SetUp()
        {
            assembler  = Substitute.For <IUserAssembler>();
            dataAccess = Substitute.For <IUserDataAccess>();

            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());

            validRegisterUserRequest = new RegisterUserRequest
            {
                DateOfBirth  = DateTime.Now,
                EmailAddress = "TEST",
                FirstName    = "TEST",
                LastName     = "TEST",
                Password     = "******",
                Username     = "******"
            };

            validValidateUserResponse = new ValidateUserResponse
            {
                LoginSuccess     = true,
                RequestReference = Guid.NewGuid(),
                User             =
                    new UserProxy
                {
                    EmailAddress = "TEST",
                    DateOfBirth  = DateTime.Now,
                    FirstName    = "TEST",
                    Id           = Guid.NewGuid(),
                    LastName     = "TEST"
                }
            };

            invalidValidateUserResponse = new ValidateUserResponse {
                Errors = { new ResponseErrorWrapper() }
            };

            validValidateUserRequest = new ValidateUserRequest
            {
                EmailAddress = "TEST",
                Password     = "******",
                Username     = "******"
            };

            invalidValidateUserRequest = new ValidateUserRequest
            {
                EmailAddress = string.Empty,
                Password     = string.Empty,
                Username     = string.Empty
            };

            validLoginViewModel = new LoginViewModel {
                EmailAddress = "TEST", Password = "******", ReturnUrl = "TEST"
            };

            invalidLoginViewModel = new LoginViewModel
            {
                EmailAddress = string.Empty,
                Password     = string.Empty,
                ReturnUrl    = string.Empty
            };

            invalidRegisterViewModel = new RegisterViewModel
            {
                AcceptTermsAndConditions = false,
                ConfirmPassword          = string.Empty,
                DateOfBirth  = DateTime.MinValue,
                EmailAddress = string.Empty,
                FirstName    = string.Empty,
                LastName     = string.Empty,
                Password     = string.Empty
            };

            validRegisterUserResponse = new RegisterUserResponse
            {
                RequestReference = Guid.NewGuid(),
                RegisterSuccess  = true
            };

            invalidRegisterUserResponse = new RegisterUserResponse
            {
                RequestReference = Guid.NewGuid(),
                Errors           =
                {
                    new ResponseErrorWrapper()
                },
                RegisterSuccess = false
            };

            validRegisterViewModel = new RegisterViewModel
            {
                AcceptTermsAndConditions = true,
                ConfirmPassword          = "******",
                DateOfBirth  = DateTime.Now,
                EmailAddress = "TEST",
                FirstName    = "TEST",
                LastName     = "TEST",
                Password     = "******"
            };

            invalidRegisterUserRequest = new RegisterUserRequest
            {
                DateOfBirth  = DateTime.MinValue,
                EmailAddress = string.Empty,
                FirstName    = string.Empty,
                LastName     = string.Empty,
                Password     = string.Empty,
                Username     = string.Empty
            };

            assembler.NewRegisterUserRequest(invalidRegisterViewModel).Returns(invalidRegisterUserRequest);
            assembler.NewRegisterUserRequest(validRegisterViewModel).Returns(validRegisterUserRequest);
            assembler.NewRegisterUserRequest(null).Throws(new Exception("TEST EXCEPTION"));

            assembler.NewValidateUserRequest(invalidLoginViewModel).Returns(invalidValidateUserRequest);
            assembler.NewValidateUserRequest(validLoginViewModel).Returns(validValidateUserRequest);
            assembler.NewValidateUserRequest(null).Throws(new Exception("TEST EXCEPTION"));

            assembler.NewClaimsIdentity(validValidateUserResponse).Returns(new ClaimsIdentity());

            dataAccess.RegisterUser(invalidRegisterUserRequest).Returns(invalidRegisterUserResponse);
            dataAccess.RegisterUser(validRegisterUserRequest).Returns(validRegisterUserResponse);

            dataAccess.ValidateUser(invalidValidateUserRequest).Returns(invalidValidateUserResponse);
            dataAccess.ValidateUser(validValidateUserRequest).Returns(validValidateUserResponse);

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