/// <summary>
        ///     Adds a goal to the database.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <AddGoalResponse> AddGoal(AddGoalRequest request)
        {
            return(await Orchestrate(async delegate {
                var dataModel = assembler.NewGoalDataModel(request.Goal);
                var addedModel = await repository.AddGoal(dataModel);

                return assembler.NewAddGoalResponse(addedModel, request.RequestReference);
            }, request));
        }
        public void NewAddGoalResponse_ValidParams_ReturnsResponse()
        {
            var test = assembler.NewAddGoalResponse(validDataModel, validGuid);

            Assert.IsNotNull(test);

            Assert.IsInstanceOf <AddGoalResponse>(test);

            Assert.AreEqual(0, test.Errors.Count);
            Assert.AreEqual(0, test.Warnings.Count);
            Assert.AreEqual(validDataModel.Id, test.Goal.Id);
            Assert.AreEqual(validDataModel.Amount, test.Goal.Amount);
            Assert.AreEqual(validDataModel.EndDate, test.Goal.EndDate);
            Assert.AreEqual(validDataModel.Complete, test.Goal.Complete);
            Assert.AreEqual(validDataModel.StartDate, test.Goal.StartDate);
            Assert.AreEqual(validDataModel.UserId, test.Goal.UserId);
            Assert.AreEqual(validGuid, test.RequestReference);

            Assert.AreSame(validDataModel.Name, test.Goal.Name);
        }
Example #3
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);
        }