예제 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BillOrchestrator" /> class.
        /// </summary>
        /// <param name="assembler">
        ///     The assembler.
        /// </param>
        /// <param name="repository">
        ///     The repository.
        /// </param>
        /// <param name="dataTransformer">
        ///     The data transformer.
        /// </param>
        /// <param name="errorHelper">
        ///     The error helper.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     Exception thrown when either the assembler, repository or data transformer are null.
        /// </exception>
        public BillOrchestrator(
            IBillAssembler assembler,
            IBillRepository repository,
            IBillDataTransformer dataTransformer,
            IErrorHelper errorHelper)
            : base(errorHelper)
        {
            if (assembler == null)
            {
                throw new ArgumentNullException(nameof(assembler));
            }

            if (repository == null)
            {
                throw new ArgumentNullException(nameof(repository));
            }

            if (dataTransformer == null)
            {
                throw new ArgumentNullException(nameof(dataTransformer));
            }

            this.assembler       = assembler;
            this.dataTransformer = dataTransformer;
            this.repository      = repository;
        }
        public void SetUp()
        {
            exportHelper = Substitute.For <IExportHelper>();

            exportHelper.ToCsv(new List <string>()).ReturnsForAnyArgs(string.Empty);
            exportHelper.ToCsv(new List <string>()).ReturnsForAnyArgs(string.Empty);
            exportHelper.ToCsv(new List <string>()).ReturnsForAnyArgs(string.Empty);

            assembler     = new BillAssembler(exportHelper);
            validUsername = "******";
            validBillId   = Guid.NewGuid();
            validUserId   = 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.MaxValue,
                UserId            = Guid.NewGuid()
            };

            validGetBillResponse = new GetBillResponse {
                Bill = validBillProxy, RequestReference = Guid.NewGuid()
            };

            validBillViewModel = new BillViewModel
            {
                Amount            = 10,
                Category          = "TEST",
                Id                = Guid.NewGuid(),
                Name              = "TEST",
                ReoccurringPeriod = TimePeriod.Daily,
                StartDate         = DateTime.MinValue,
                UserId            = Guid.NewGuid()
            };

            validAddBillResponse = new AddBillResponse {
                Bill = validBillProxy, RequestReference = Guid.NewGuid()
            };

            validEditBillResponse = new EditBillResponse {
                Bill = validBillProxy, RequestReference = Guid.NewGuid()
            };

            validGetBillsForUserResponse = new GetBillsForUserResponse
            {
                Bills = new List <BillProxy> {
                    validBillProxy
                },
                RequestReference = Guid.NewGuid()
            };
        }
 public void TearDown()
 {
     assembler             = null;
     validUsername         = null;
     validBillViewModel    = null;
     validAddBillResponse  = null;
     validGetBillResponse  = null;
     validEditBillResponse = null;
     validBillProxy        = null;
     validBillId           = Guid.Empty;
 }
예제 #4
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="BillOrchestrator" /> class.
        /// </summary>
        /// <param name="assembler">
        ///     The assembler.
        /// </param>
        /// <param name="dataAccess">
        ///     The data access.
        /// </param>
        /// <param name="errorHelper">
        ///     The error helper.
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        ///     Exception thrown when the assembler or data access objects are null.
        /// </exception>
        public BillOrchestrator(IBillAssembler assembler, IBillDataAccess dataAccess, IErrorHelper errorHelper)
            : base(errorHelper)
        {
            if (assembler == null)
            {
                throw new ArgumentNullException(nameof(assembler));
            }

            if (dataAccess == null)
            {
                throw new ArgumentNullException(nameof(dataAccess));
            }

            this.assembler  = assembler;
            this.dataAccess = dataAccess;
        }
 public void TearDown()
 {
     orchestrator              = null;
     assembler                 = null;
     dataAccess                = null;
     validViewModel            = null;
     validAddBillRequest       = null;
     validAddBillResponse      = null;
     invalidAddBillRequest     = null;
     invalidAddBillResponse    = null;
     validDeleteBillRequest    = null;
     validDeleteBillResponse   = null;
     invalidDeleteBillRequest  = null;
     invalidDeleteBillResponse = null;
     validGetBillRequest       = null;
     validGetBillResponse      = null;
     invalidGetBillRequest     = null;
     invalidGetBillResponse    = null;
     validBillProxy            = null;
     invalidBillViewModel      = null;
 }
예제 #6
0
        public void SetUp()
        {
            validGuid      = Guid.NewGuid();
            validDataModel = new BillDataModel
            {
                Amount   = 1,
                Category =
                    new CategoryDataModel
                {
                    CreationTime = DateTime.Now,
                    Id           = validGuid,
                    Name         = "TEST"
                },
                CategoryId        = validGuid,
                CreationTime      = DateTime.Now,
                Id                = validGuid,
                Name              = "TEST",
                ReoccurringPeriod = 1,
                StartDate         = DateTime.Now,
                UserId            = validGuid
            };

            validProxy = new BillProxy
            {
                Amount   = 1,
                Category = new CategoryProxy {
                    Id = validGuid, Name = "TEST"
                },
                CategoryId        = validGuid,
                Id                = validGuid,
                Name              = "TEST",
                ReoccurringPeriod = 1,
                StartDate         = DateTime.Now,
                UserId            = validGuid
            };

            assembler = new BillAssembler();
        }
예제 #7
0
 public void TearDown()
 {
     assembler = null;
 }
예제 #8
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);
        }
예제 #9
0
 public void TearDown()
 {
     orchestrator = null;
     assembler    = null;
     repository   = null;
 }
        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);
        }