Пример #1
0
        public UnitTestUser()
        {
            var ioptions   = new Mock <IOptions <EmailConfig> >();
            var cbaoptions = new Mock <EmailConfig>();

            ioptions.Setup(s => s.Value).Returns(cbaoptions.Object);
            _emailConfig = ioptions.Object;

            cbaoptions.SetupAllProperties();

            _dbOptions = new DbContextOptionsBuilder <CBAContext>()
                         .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            _cbaContext = new CBAContext(_dbOptions);

            _mockUserStore   = new Mock <IUserStore <CBAUser> >();
            _mockUserManager = new Mock <UserManager <CBAUser> >(_mockUserStore.Object,
                                                                 null, null, null, null, null, null, null, null);

            _emailService = new Mock <IEmailService>();
            _emailService.Setup(x => x.SendEmail(It.IsAny <EmailConfig>(), It.IsAny <Email>())).ReturnsAsync(true);

            _crypto = new Mock <ICryptography>();

            _createReturnHTML = new Mock <ICreateReturnHTML>();
            _userController   = new UserController(_cbaContext, _crypto.Object, _mockUserManager.Object, _emailService.Object, _emailConfig, _createReturnHTML.Object);
        }
        public void CreateInvoiceShould_RequireProperties()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var service = new InvoiceService(context, options, mapper, pdf, logger);
            var invoice = new InvoiceForCreationDto()
            {
                ClientName          = "",
                ClientContactPerson = "Glen Clarke",
                ClientContact       = "530/546A Memorial Ave\\r\\nChristchurch Airport\\r\\nChristchurch 8053",
                InvoiceLine         = null
            };

            // act
            bool success = false;

            try
            {
                var result = service.CreateInvoice(invoice);
            }
            catch (ValidationException)
            {
                success = true;
            }
            // assert
            Assert.IsTrue(success);
        }
Пример #3
0
 public ChangePasswordController(CBAContext context, ICryptography crypto, IEmailService emailService, IOptions <EmailConfig> emailConfig, IHostingEnvironment env)
 {
     _context          = context;
     _crypto           = crypto;
     this.emailService = emailService;
     this.emailConfig  = emailConfig.Value;
     _env = env;
 }
Пример #4
0
        public AccountController(CBAContext context,
                                 ICryptography crypto,
                                 SignInManager <CBAUser> signInManager,
                                 UserManager <CBAUser> userManager)
        {
            _context = context;

            //Dependency Injection
            _crypto        = crypto;
            _signInManager = signInManager;
            _userManager   = userManager;
        }
Пример #5
0
 public InvoiceService(
     CBAContext context,
     IOptions <CBAOptions> optionsAccessor,
     IMapper mapper,
     IPdfService pdfService,
     ILogger <InvoiceService> logger)
 {
     this.context    = context;
     options         = optionsAccessor.Value;
     this.mapper     = mapper;
     this.pdfService = pdfService;
     this.logger     = logger;
 }
        public void ModifyInvoice_ReplacesInvoiceLines()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var seeder  = new CBASeeder(context, cryptography);

            seeder.Seed();

            var service         = new InvoiceService(context, options, mapper, pdf, logger);
            var originalInvoice = context.Invoice.Include("InvoiceLine")
                                  .SingleOrDefault(t => t.InvoiceNumber == "ABNZ000420");

            var modifiedInvoice = new InvoiceForUpdateDto()
            {
                // all fields should be the same except InvoiceLine
                ClientName          = originalInvoice.ClientName,
                ClientContact       = originalInvoice.ClientContact,
                ClientContactPerson = originalInvoice.ClientContactPerson,
                DateDue             = originalInvoice.DateDue,
                Email = originalInvoice.Email,
                PurchaseOrderNumber = originalInvoice.PurchaseOrderNumber,

                InvoiceLine = new List <InvoiceLineDto>()
                {
                    new InvoiceLineDto()
                    {
                        Description = "New Dinner",
                        Amount      = 50
                    },
                    new InvoiceLineDto()
                    {
                        Description = "New Cookie",
                        Amount      = 10
                    }
                }
            };

            var expectedLineCount = context.InvoiceLine.Count()
                                    - originalInvoice.InvoiceLine.Count()
                                    + modifiedInvoice.InvoiceLine.Count();

            // act
            service.ModifyInvoice("ABNZ000420", modifiedInvoice);
            var lineCount = context.InvoiceLine.Count();

            // assert
            Assert.AreEqual(expectedLineCount, lineCount);
        }
        public void DeleteInvoice_DeletesDraftInvoice()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var seeder  = new CBASeeder(context, cryptography);

            seeder.Seed();

            var service = new InvoiceService(context, options, mapper, pdf, logger);

            // act
            bool result = service.DeleteInvoice("ABNZ000420");

            // assert
            Assert.AreEqual(true, result);
        }
        public void ModifyInvoice_UpdatesInvoiceLines_WhenOnlyInvoiceLinesModified()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var seeder  = new CBASeeder(context, cryptography);

            seeder.Seed();

            var     service         = new InvoiceService(context, options, mapper, pdf, logger);
            Invoice invoiceToUpdate = context.Invoice.Include("InvoiceLine")
                                      .SingleOrDefault(t => t.InvoiceNumber == "ABNZ000420");

            InvoiceForUpdateDto invoice = new InvoiceForUpdateDto()
            {
                // all fields should be the same except InvoiceLine
                ClientName          = invoiceToUpdate.ClientName,
                ClientContact       = invoiceToUpdate.ClientContact,
                ClientContactPerson = invoiceToUpdate.ClientContactPerson,
                DateDue             = invoiceToUpdate.DateDue,
                Email = invoiceToUpdate.Email,
                PurchaseOrderNumber = invoiceToUpdate.PurchaseOrderNumber
            };

            invoice.InvoiceLine = new List <InvoiceLineDto>()
            {
                new InvoiceLineDto()
                {
                    Description = "New Dinner",
                    Amount      = 50
                },
                new InvoiceLineDto()
                {
                    Description = "New Cookie",
                    Amount      = 10
                }
            };

            // act
            service.ModifyInvoice("ABNZ000420", invoice);

            // assert
            var cleancontext = new CBAContext(dboptions);

            Assert.AreEqual(2, cleancontext.Invoice.Include("InvoiceLine")
                            .SingleOrDefault(t => t.InvoiceNumber == "ABNZ000420").InvoiceLine.Count());
        }
Пример #9
0
        //private ILogger _logger;

        public UserController(CBAContext context,
                              ICryptography crypto,
                              UserManager <CBAUser> userManager,
                              //SignInManager<CBAUser> signInManager
                              //ILogger logger,
                              IEmailService emailService,
                              IOptions <EmailConfig> emailConfig,
                              ICreateReturnHTML createReturnHTML
                              )
        {
            _context = context;
            //Dependency Injection
            _crypto      = crypto;
            _userManager = userManager;
            //_logger = logger;
            _emailService     = emailService;
            _emailConfig      = emailConfig.Value;
            _createReturnHTML = createReturnHTML;
        }
        public void DeleteInvoice_RejectsNonDraftInvoice()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var seeder  = new CBASeeder(context, cryptography);

            seeder.Seed();

            var service = new InvoiceService(context, options, mapper, pdf, logger);

            // act
            bool result = false;

            try {
                service.DeleteInvoice("ABNZ000421");
            }
            catch (ArgumentException) { result = true; }

            // assert
            Assert.AreEqual(true, result);
        }
Пример #11
0
        public UnitTestAccount()
        {
            _dbOptions = new DbContextOptionsBuilder <CBAContext>()
                         .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            _cbaContext = new CBAContext(_dbOptions);

            //Dependency Injection
            _crypto        = new Mock <ICryptography>();
            _mockUserStore = new Mock <IUserStore <CBAUser> >();

            var contextAccessor      = new Mock <IHttpContextAccessor>();
            var userPrincipalFactory = new Mock <IUserClaimsPrincipalFactory <CBAUser> >();

            _mockUserManager = new Mock <UserManager <CBAUser> >(_mockUserStore.Object,
                                                                 null, null, null, null, null, null, null, null);

            _mockSignInManager = new Mock <SignInManager <CBAUser> >(_mockUserManager.Object,
                                                                     contextAccessor.Object, userPrincipalFactory.Object, null, null, null);

            _accountController = new AccountController(_cbaContext, _crypto.Object, _mockSignInManager.Object, _mockUserManager.Object);
        }
        public void CreateInvoiceShould_CreateInvoice()
        {
            // arrange
            var context = new CBAContext(dboptions);
            var service = new InvoiceService(context, options, mapper, pdf, logger);

            var invoice = new InvoiceForCreationDto()
            {
                LoginId             = "LoginFoo",
                ClientName          = "Electrocal Commission",
                ClientContactPerson = "Glen Clarke",
                ClientContact       = "530/546A Memorial Ave\\r\\nChristchurch Airport\\r\\nChristchurch 8053",
                Email       = "*****@*****.**",
                InvoiceLine = new List <InvoiceLineDto>()
                {
                    new InvoiceLineDto()
                    {
                        Description = "Fundraising Dinner",
                        Amount      = 25
                    },
                    new InvoiceLineDto()
                    {
                        Description = "Cake",
                        Amount      = 35
                    }
                }
            };

            // act
            var result = service.CreateInvoice(invoice);

            // assert
            Assert.IsTrue(result != null);
            using (var cleancontext = new CBAContext(dboptions))
            {
                Assert.IsTrue(context.Invoice.Any());
                Assert.IsTrue(context.Invoice.FirstOrDefault().InvoiceLine.Count() == 2);
            }
        }