コード例 #1
0
        public void given_quote_db_entity_quote_repository_should_save_to_database()
        {
            // setup
            var repository = new QuoteRepository();
            var quote      = new CalculateQuoteDbModel {
                Title           = "Mr",
                Name            = "BumbleBee",
                Mobile          = "0838386288",
                Email           = "*****@*****.**",
                FinancialAmount = 5500,
                Repayments      = 300,
                DateTimeAdded   = DateTime.Now
            };

            // act
            repository.SaveQuote(quote);

            // assert
            var result = repository.GetQuoteBy(1);

            Assert.Equal(quote.Title, result.Title);
            Assert.Equal(quote.Mobile, result.Mobile);
            Assert.Equal(quote.Name, result.Name);
            Assert.Equal(quote.Repayments, result.Repayments);
        }
コード例 #2
0
        public ActionResult QuoteDetail(Guid id)
        {
            QuoteRepository repositpory = new QuoteRepository();

            QuoteDetailsViewModel model = new QuoteDetailsViewModel();

            var             quoteInfo       = repositpory.GetQuoteById(id);
            var             currentUserName = User.Identity.Name;
            ApplicationUser user            = new ApplicationUser();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                user = db.Users.FirstOrDefault(u => u.UserName == currentUserName);
            }

            model.Name          = user.FirstName + " " + user.LastName;
            model.Email         = user.Email;
            model.Id            = quoteInfo.Id;
            model.IsPurchased   = quoteInfo.IsPurchased;
            model.QuoteInfoList = quoteInfo.QuoteInfoList;
            model.QuotePrice    = quoteInfo.QuotePrice;
            model.StartAddress  = quoteInfo.StartAddress;
            model.UserId        = quoteInfo.UserId;
            model.Distance      = quoteInfo.Distance;
            model.EndAddress    = quoteInfo.EndAddress;

            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> DeleteQuote([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = _userManagement.Find(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var repo = new QuoteRepository(_context);
            var q    = repo.Search(id);

            if (q == null)
            {
                // return 404?
                return(NotFound());
            }
            else
            {
                if (q.CreatedByUserId != user.Id)
                {
                    // Not created by this user??
                    return(Unauthorized());
                }
            }

            repo.DeleteQuote(q);

            await _context.SaveChangesAsync();

            return(Ok(user));
        }
コード例 #4
0
        public HomeController()
        {
            DatabaseContext context   = new DatabaseContext();
            QuoteRepository quoteRepo = new QuoteRepository(context);

            transactionsService = new TransactionsService(quoteRepo);
        }
コード例 #5
0
        public void TestGetCurrencyList()
        {
            IQuoteRepository quoteService = new QuoteRepository();
            var list = quoteService.GetCurrencyList();

            Assert.AreNotEqual(0, list.Count);
        }
コード例 #6
0
 public QuoteBusiness(IUnitOfWork _unitOfWork)
 {
     unitOfWork           = _unitOfWork;
     quoteRepository      = new QuoteRepository(unitOfWork);
     salesOrderRepository = new SalesOrderRepository(unitOfWork);
     productQuoteAssociationRepository = new ProductQuoteAssociationRepository(unitOfWork);
 }
コード例 #7
0
        public void CreateDeliveriesFromPendingItems_ValidPendingDeliveryItems_DeliveriesCreated()
        {
            var dispatcher     = MockRepository.GenerateMock <IQueueDispatcher <IMessage> >();
            var userRepository = new UserAccountRepository();
            var user           = userRepository.GetByEmail("*****@*****.**", false);
            var userContext    = new TestUserContext(user);

            var quoteRepository        = new QuoteRepository();
            var quoteItemRepository    = new QuoteItemRepository();
            var customerRepository     = new CustomerRepository();
            var jobRepository          = new JobRepository();
            var jobItemRepository      = new JobItemRepository();
            var listItemRepository     = new ListItemRepository();
            var entityIdProvider       = new DirectEntityIdProvider();
            var instrumentRepository   = new InstrumentRepository();
            var deliveryRepository     = new DeliveryRepository();
            var deliveryItemRepository = new DeliveryItemRepository();

            var customerId1 = Guid.NewGuid();
            var customerId2 = Guid.NewGuid();
            var job1Id      = Guid.NewGuid();
            var job2Id      = Guid.NewGuid();
            var job3Id      = Guid.NewGuid();
            var jobItem1Id  = Guid.NewGuid();
            var jobItem2Id  = Guid.NewGuid();
            var jobItem3Id  = Guid.NewGuid();
            var jobItem4Id  = Guid.NewGuid();
            var jobItem5Id  = Guid.NewGuid();
            var jobItem6Id  = Guid.NewGuid();
            var jobItem7Id  = Guid.NewGuid();
            var jobItem8Id  = Guid.NewGuid();
            var jobItem9Id  = Guid.NewGuid();

            CreateDeliveriesFromPendingItemsHelper.CreateContextForPendingItemTests(
                customerId1, customerId2, job1Id, job2Id, job3Id, jobItem1Id, jobItem2Id, jobItem3Id, jobItem4Id, jobItem5Id, jobItem6Id, jobItem7Id, jobItem8Id, jobItem9Id);

            var deliveryItemService =
                new DeliveryItemService(
                    userContext, deliveryRepository, deliveryItemRepository, jobItemRepository, quoteItemRepository, listItemRepository, customerRepository, dispatcher);
            var deliveryService = new DeliveryService(userContext, deliveryRepository, deliveryItemService, customerRepository, entityIdProvider, dispatcher);

            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem1Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem2Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem3Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem4Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem5Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem6Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem7Id, customerId1, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem8Id, customerId2, "some notes");
            deliveryItemService.CreatePending(Guid.NewGuid(), jobItem9Id, customerId2, "some notes");
            deliveryService.CreateDeliveriesFromPendingItems();

            var deliveries = deliveryService.GetDeliveries().ToList();

            Assert.AreEqual(2, deliveries.Count);
            var deliveryItems = deliveryItemService.GetDeliveryItems(deliveries[0].Id).ToList();

            Assert.AreEqual(7, deliveryItems.Count);
        }
コード例 #8
0
 public Quotes(
     QuoteRepository quoteRepository,
     IForumViewResult forumViewResult
     )
 {
     QuoteRepository = quoteRepository;
     ForumViewResult = forumViewResult;
 }
コード例 #9
0
 public QuoteSubscriber(QuoteRepository quoteRepository, IBlobStorage blobStorage, QuoteMemoryCache <Quote> quoteMemoryCache, AppConfig config, ILogger <QuoteSubscriber> logger)
 {
     _quoteRepository  = quoteRepository;
     _blobStorage      = blobStorage;
     _quoteMemoryCache = quoteMemoryCache;
     _config           = config;
     _logger           = logger;
     _container        = DateTime.UtcNow.ToIsoDateTime().Replace(":", "-").Replace(" ", "t");
 }
コード例 #10
0
        public ActionResult Quote(string start, string end, string distance)
        {
            QuoteRepository repositpory = new QuoteRepository();

            var model = repositpory.GenerateQuote(start, end, distance, User.Identity.Name);



            return(RedirectToAction("QuoteDetail", new { id = model.Id }));
        }
コード例 #11
0
 public Sidebar(
     AccountRepository accountRepository,
     NotificationRepository notificationRepository,
     QuoteRepository quoteRepository
     )
 {
     AccountRepository      = accountRepository;
     NotificationRepository = notificationRepository;
     QuoteRepository        = quoteRepository;
 }
コード例 #12
0
        public QuoteViewModel Get(int id)
        {
            var user = _userManagement.Find(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var repo = new QuoteRepository(_context);

            return(id == 0
                                ? new QuoteViewModel()
                                : repo.Search(id).ToViewModel(user));
        }
コード例 #13
0
 public QuoteViewComponent(
     ApplicationDbContext dbContext,
     AccountRepository accountRepository,
     QuoteRepository quoteRepository
     )
 {
     DbContext         = dbContext;
     AccountRepository = accountRepository;
     QuoteRepository   = quoteRepository;
 }
コード例 #14
0
        public async Task <IActionResult> Delete(int id)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await QuoteRepository.Delete(id);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse));
            }

            return(ForumViewResult.RedirectToReferrer(this));
        }
コード例 #15
0
        public async Task <IActionResult> Edit(InputModels.QuotesInput input)
        {
            if (ModelState.IsValid)
            {
                var serviceResponse = await QuoteRepository.Edit(input);

                return(await ForumViewResult.RedirectFromService(this, serviceResponse));
            }

            return(ForumViewResult.RedirectToReferrer(this));
        }
コード例 #16
0
        // GET: Quotes
        public ActionResult Index()
        {
            QuoteRepository repo   = new QuoteRepository();
            string          userid = null;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                userid = db.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefault().Id;
            }
            var list = repo.GetQuotesList(userid);

            return(View(list));
        }
コード例 #17
0
        public IActionResult Search(string search)
        {
            if (String.IsNullOrEmpty(search))
            {
                return(View("Index"));
            }

            ViewBag.Search = search.Trim();

            QuoteRepository repository = new QuoteRepository();

            return(View("Index", repository.Search(search.Trim())));
        }
コード例 #18
0
        public QuoteRepositoryIntegrationTests()
        {
            cs = new ConnectionStringProvider();

            Conn = new SqlConnection(cs.ConnectionString);

            var log = new SeriLogFacility <QuoteRepository>(Log.Logger);

            Sut = new QuoteRepository(Conn, log);

            FluentMapper.EntityMaps.Clear();
            FluentMapper.Initialize(cfg => cfg.AddMap(new QuoteSchema()));
            Conn.Open();
        }
コード例 #19
0
        public IActionResult Save([FromBody] QuoteViewModel quote)
        {
            var user = _userManagement.Find(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var   repo = new QuoteRepository(_context);
            Quote q;

            // New Quote
            if (quote.Id == 0)
            {
                q = repo.CreateQuote(user);
            }
            // Update existing
            else
            {
                q = repo.Search(quote.Id);
                if (q == null)
                {
                    // return 404?
                    return(NotFound());
                }
                else
                {
                    if (q.CreatedByUserId != user.Id)
                    {
                        // Not created by this user??
                        return(Unauthorized());
                    }
                }
            }

            q.Text = quote.Text;

            // Check if Author has changed
            if (q.Author == null || q.Author.Name != quote.Author)
            {
                q.Author = repo.FindAuthor(quote.Author);
                if (q.Author == null)
                {
                    q.Author = new Author()
                    {
                        Name = quote.Author,
                    };
                }
            }

            _context.SaveChanges();

            return(Ok(quote));
        }
コード例 #20
0
 public QuoteMutation(QuoteRepository quoteRepository)
 {
     FieldAsync <QuoteType>(
         "createQuote",
         arguments: new QueryArguments(
             new QueryArgument <NonNullGraphType <QuoteInputType> > {
         Name = "quote"
     }),
         resolve: async context =>
     {
         var quote = context.GetArgument <Quote>("quote");
         return(await context.TryAsyncResolve(
                    async c => await quoteRepository.AddQuote(quote)));
     });
 }
コード例 #21
0
        private async Task upVoteTestSuccess(ApplicationDbContext ctx)
        {
            var repository = new QuoteRepository(ctx);
            SlackEventRequestModel upvoteRequest = await getSlackEventRequestModel();

            await repository.UpvoteAsync(upvoteRequest);

            var quoteInDb = await ctx.Quote.Include(q => q.Votes)
                            .FirstOrDefaultAsync();

            var vote = quoteInDb.Votes[0];

            Object.Equals(1, vote.Vote);
            Object.Equals(vote.UserSlackId, "SLACK");
        }
コード例 #22
0
        private async Task upvoteQuoteTwiceTest()
        {
            using (var ctx = new ApplicationDbContext(options))
            {
                var repository = new QuoteRepository(ctx);
                SlackEventRequestModel upvoteRequest = await getSlackEventRequestModel();

                await repository.UpvoteAsync(upvoteRequest);

                await Assert.ThrowsAnyAsync <Exception>(
                    async() =>
                    await repository.UpvoteAsync(upvoteRequest)
                    );
            }
        }
コード例 #23
0
        private async Task addQuoteTst(ApplicationDbContext ctx)
        {
            var repository = new QuoteRepository(ctx);
            var userId     = await AddUser(false);

            var snitchId = await AddUser(true);

            var quote = GetFilledQuoteModel(userId, snitchId);
            await repository.AddQuoteAsync(quote);

            var quoteDb = ctx.Quote.FirstOrDefault();

            Assert.NotNull(quoteDb);
            Assert.Equal(quote.Date, quoteDb.Date);
        }
コード例 #24
0
        public async Task AddQuoteTst()
        {
            using (var ctx = new ApplicationDbContext(options))
            {
                var repository = new QuoteRepository(ctx);
                var userId     = await AddUser();

                var quote = GetFilledQuoteModel(userId);
                await repository.AddQuoteAsync(quote);


                var quoteDb = ctx.Quote.FirstOrDefault();

                Assert.NotNull(quoteDb);
                Assert.Equal(quote.Date, quoteDb.Date);
            }
        }
コード例 #25
0
        public QuoteRepositoryTests()
        {
            _repository = new QuoteRepository();
            var service = new QuoteService(_repository);

            _mockQuoteSetting = new Mock <IOptions <QuoteSetting> >();
            var _quoteSetting = new QuoteSetting
            {
                MinAmountRequired = 2100,
                MaxAmountRequired = 15000,
                MinTerm           = 3,
                MaxTerm           = 36
            };

            _mockQuoteSetting.Setup(q => q.Value).Returns(_quoteSetting);

            _homeController = new HomeController(service, _mockQuoteSetting.Object);
        }
コード例 #26
0
        public void GetRandomQuote_ReturnQuote1WhenRequested()
        {
            _fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny <int>(), It.IsAny <int>())).Returns(0);

            var sut = new QuoteRepository(_xDocLoader)
            {
                RandomNumberGenerator = _fakeNumberGenerator.Object
            };

            Quote quote = sut.GetRandomQuote(QuotesFilesPath);

            const int    expectedId     = 1;
            const string expectedText   = "I am the wisest man alive for I know one thing, and that is that I know nothing";
            const string expectedAuthor = "Socrates";

            Assert.AreEqual(expectedId, quote.Id);
            Assert.AreEqual(expectedText, quote.Text);
            Assert.AreEqual(expectedAuthor, quote.Author);
        }
コード例 #27
0
        public void GetRandomQuote_ReturnQuote2WhenRequested()
        {
            _fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny <int>(), It.IsAny <int>())).Returns(1);

            var sut = new QuoteRepository(_xDocLoader)
            {
                RandomNumberGenerator = _fakeNumberGenerator.Object
            };

            Quote quote = sut.GetRandomQuote(QuotesFilesPath);

            const int    expectedId     = 2;
            const string expectedText   = "Any man who reads too much and uses his own brain too little falls into lazy habits of thinking.";
            const string expectedAuthor = "David Brinkley";

            Assert.AreEqual(expectedId, quote.Id);
            Assert.AreEqual(expectedText, quote.Text);
            Assert.AreEqual(expectedAuthor, quote.Author);
        }
コード例 #28
0
        public void GetRandomQuote_ReturnQuote3WhenRequested()
        {
            _fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny <int>(), It.IsAny <int>())).Returns(2);

            var sut = new QuoteRepository(_xDocLoader)
            {
                RandomNumberGenerator = _fakeNumberGenerator.Object
            };

            Quote quote = sut.GetRandomQuote(QuotesFilesPath);

            const int    expectedId     = 3;
            const string expectedText   = "Failure is simply the opportunity to begin again, this time more intelligently.";
            const string expectedAuthor = "Henry Ford";

            Assert.AreEqual(expectedId, quote.Id);
            Assert.AreEqual(expectedText, quote.Text);
            Assert.AreEqual(expectedAuthor, quote.Author);
        }
コード例 #29
0
        public void GetRandomQuote_ReturnQuote4WhenRequested()
        {
            _fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny <int>(), It.IsAny <int>())).Returns(3);

            var sut = new QuoteRepository(_xDocLoader)
            {
                RandomNumberGenerator = _fakeNumberGenerator.Object
            };

            Quote quote = sut.GetRandomQuote(QuotesFilesPath);

            const int    expectedId     = 4;
            const string expectedText   = "Instead of getting married again, I'm going to find a woman I don't like and just give her a house.";
            const string expectedAuthor = "Rod Stewart";

            Assert.AreEqual(expectedId, quote.Id);
            Assert.AreEqual(expectedText, quote.Text);
            Assert.AreEqual(expectedAuthor, quote.Author);
        }
コード例 #30
0
        public static TRepository Get <TRepository, TEntity>(bool autoDetectChangesEnabled = true)
            where TRepository : Repository <TEntity>
            where TEntity : BaseModel
        {
            Logger.InstanceVerbose.LogFunctionEntry(typeof(RepositoryFactory).Name, String.Format("Repository<{0}>", typeof(TEntity).Name));

            Expression <Func <TEntity, bool> > filter;
            String username;
            bool   throwsUnauthorized;

            if (filters.ContainsKey(typeof(TEntity)))
            {
                GetActionTypes action;
                filter             = GetFilter <TEntity>(out action);
                username           = Thread.CurrentPrincipal.Identity.Name;
                throwsUnauthorized = action == GetActionTypes.ThrowsUnauthorizedException;
            }
            else
            {
                filter             = null;
                username           = null;
                throwsUnauthorized = true;
            }

            Object repo;

            if (typeof(TRepository) == typeof(Repository <TEntity>))
            {
                repo = new Repository <TEntity>(username, filter, throwsUnauthorized, autoDetectChangesEnabled);
            }
            else if (typeof(TRepository) == typeof(QuoteRepository))
            {
                repo = new QuoteRepository(username, filter as Expression <Func <Models.Quote, bool> >, throwsUnauthorized, autoDetectChangesEnabled); // Add same params as below.
            }
            else
            {
                throw new NotImplementedException();
            }

            Logger.InstanceVerbose.LogFunctionExit(typeof(RepositoryFactory).Name, String.Format("Repository<{0}>", typeof(TEntity).Name));

            return(repo as TRepository);
        }
コード例 #31
0
        public void MakeACallTo_DefaultQuoteIf_LoadXml_ReturnsANull_XDocument()
        {
            var fakeXmlLoader = new Mock<IXDocumentLoader>();
            fakeXmlLoader.Setup(x => x.LoadXDocument(It.IsAny<string>())).Returns(() => null);

            var fakeNumberGenerator = new Mock<IRandomNumberGenerator>();
            fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny<int>(), It.IsAny<int>())).Returns(1);

            var fakeDefaultQuoteGenerator = new Mock<DefaultQuoteGenerator>();

            var sut = new QuoteRepository(fakeXmlLoader.Object)
            {
                RandomNumberGenerator = fakeNumberGenerator.Object,
                DefaultQuoteGenerator = fakeDefaultQuoteGenerator.Object
            };

            sut.GetRandomQuote(filePath: "test");

            fakeDefaultQuoteGenerator.Verify(x => x.GetDefaultQuote(), Times.Once());
        }
コード例 #32
0
        public void MakeACallTo_GetDefaultQuote_IfFilePathParameterIsAn_EmptyString()
        {
            var fakeXmlLoader = new Mock<IXDocumentLoader>();
            fakeXmlLoader.Setup(x => x.LoadXDocument(It.IsAny<string>())).Returns(_inMemoryXDoc);

            var fakeNumberGenerator = new Mock<IRandomNumberGenerator>();
            fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny<int>(), It.IsAny<int>())).Returns(1);

            var fakeDefaultQuoteGenerator = new Mock<DefaultQuoteGenerator>();

            var sut = new QuoteRepository(fakeXmlLoader.Object)
            {
                RandomNumberGenerator = fakeNumberGenerator.Object,
                DefaultQuoteGenerator = fakeDefaultQuoteGenerator.Object
            };

            sut.GetRandomQuote(filePath: string.Empty);

            fakeDefaultQuoteGenerator.Verify(x => x.GetDefaultQuote(), Times.Once());
        }
コード例 #33
0
        public void ReturnQuoteOneIfRandomIndexIsOne()
        {
            var fakeXmlLoader = new Mock<IXDocumentLoader>();
            fakeXmlLoader.Setup(x => x.LoadXDocument(It.IsAny<string>())).Returns(Mother.GetXDocument);

            var fakeNumberGenerator = new Mock<IRandomNumberGenerator>();
            fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny<int>(), It.IsAny<int>())).Returns(1);

            var fakeDefaultQuoteGenerator = new Mock<DefaultQuoteGenerator>();

            var sut = new QuoteRepository(fakeXmlLoader.Object)
            {
                RandomNumberGenerator = fakeNumberGenerator.Object,
                DefaultQuoteGenerator = fakeDefaultQuoteGenerator.Object
            };

            Quote quote = sut.GetRandomQuote(filePath: "test");

            fakeDefaultQuoteGenerator.Verify(x => x.GetDefaultQuote(), Times.Exactly(1));
        }
コード例 #34
0
        public void MakeACallTo_GetDefaultQuote_If_XElementIs_Null()
        {
            var nullElementXDoc = new XDocument();

            var fakeXmlLoader = new Mock<IXDocumentLoader>();
            fakeXmlLoader.Setup(x => x.LoadXDocument(It.IsAny<string>())).Returns(nullElementXDoc);

            var fakeNumberGenerator = new Mock<IRandomNumberGenerator>();
            fakeNumberGenerator.Setup(x => x.GetRandomNumber(It.IsAny<int>(), It.IsAny<int>())).Returns(1);

            var fakeDefaultQuoteGenerator = new Mock<DefaultQuoteGenerator>();

            var sut = new QuoteRepository(fakeXmlLoader.Object)
            {
                RandomNumberGenerator = fakeNumberGenerator.Object,
                DefaultQuoteGenerator = fakeDefaultQuoteGenerator.Object
            };

            sut.GetRandomQuote(filePath: "test");

            fakeDefaultQuoteGenerator.Verify(x => x.GetDefaultQuote(), Times.Exactly(1));
        }