Пример #1
0
        /// <summary>
        ///     Gets the goals for a specific user.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <GetGoalsForUserResponse> GetGoalsForUser(GetGoalsForUserRequest request)
        {
            return(await Orchestrate(async delegate {
                var goals = await repository.GetGoalsForUser(request.UserId);

                return assembler.NewGetGoalsForUserResponse(goals, request.RequestReference);
            }, request));
        }
Пример #2
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);
        }
Пример #3
0
 /// <summary>
 /// Sends an HTTP GET request to obtain all the goals for a given user.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns>
 /// The response object.
 /// </returns>
 public async Task <GetGoalsForUserResponse> GetGoalsForUser(GetGoalsForUserRequest request)
 {
     return(await Get <GetGoalsForUserResponse>(request.FormatRequestUri(), request.Username));
 }
Пример #4
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);
        }
Пример #5
0
        public async Task <IHttpActionResult> GetGoalsForUser([FromUri] GetGoalsForUserRequest request)
        {
            var response = await orchestrator.GetGoalsForUser(request);

            return(Ok(response));
        }