public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var filters = new DealSearchFilters
                {
                    ExactMatch = true,
                    Status     = DealStatus.lost,
                    PageSize   = 1,
                    PageCount  = 1,
                    StartPage  = 0,
                };

                await client.Search("name", filters);

                Received.InOrder(async() =>
                {
                    await connection.SearchAll <SearchResult <SimpleDeal> >(Arg.Is <Uri>(u => u.ToString() == "deals/search"),
                                                                            Arg.Is <Dictionary <string, string> >(d => d.Count == 3 &&
                                                                                                                  d["term"] == "name" &&
                                                                                                                  d["exact_match"] == "True" &&
                                                                                                                  d["status"] == "lost"),
                                                                            Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                                                                                o.PageCount == 1 &&
                                                                                                o.StartPage == 0));
                });
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var filters = new DealParticipantFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 0,
                };

                await client.GetParticipants(123, filters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <DealParticipant>(
                        Arg.Is <Uri>(u => u.ToString() == "deals/123/participants"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["id"] == "123"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
            public void GetProductsForDeal()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var dealProductFilters = new DealProductFilters
                {
                    PageSize           = 1,
                    PageCount          = 1,
                    StartPage          = 0,
                    IncludeProductData = "1"
                };

                client.GetProductsForDeal(1, dealProductFilters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <DealProduct>(
                        Arg.Is <Uri>(u => u.ToString() == "deals/1/products"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["include_product_data"] == "1"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var filters = new DealFilters
                {
                    PageSize  = 1,
                    PageCount = 1,
                    StartPage = 0,
                    Status    = DealStatus.lost,
                };

                await client.GetAllForCurrent(filters);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <Deal>(
                        Arg.Is <Uri>(u => u.ToString() == "deals"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 2 &&
                                                              d["owned_by_you"] == "1" &&
                                                              d["status"] == "lost"),
                        Arg.Is <ApiOptions>(o => o.PageSize == 1 &&
                                            o.PageCount == 1 &&
                                            o.StartPage == 0));
                });
            }
            public async Task EnsuresSearchTermIsMoreThan2Characters()
            {
                var client = new DealsClient(Substitute.For <IApiConnection>());

                var exception = await Assert.ThrowsAsync <ArgumentException>(() => client.Search("p", DealSearchFilters.None));

                Assert.Equal("The search term must have at least 2 characters (Parameter 'term')", exception.Message);
            }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MockEmailContentCreatorFactory"/> class.
        /// </summary>
        /// <param name="storageAccount">
        /// The storage account.
        /// </param>
        /// <param name="dealsServerBaseAddress">
        /// The deals server base address.
        /// </param>
        /// <param name="settingsContainerClient">
        /// The settings container client.
        /// </param>
        public MockEmailContentCreatorFactory(string storageAccount, Uri dealsServerBaseAddress, SettingsContainerClient settingsContainerClient)
        {
            MockModelContentCreator mockModelContentCreator = new MockModelContentCreator();
            DealsClient             dealsClient             = new DealsClient(dealsServerBaseAddress, ClientName);
            IDealsSelector          dealsSelector           = new NaiveDealsSelector(dealsClient);
            EmailTemplatesFetcher <DealsEmailModel> emailTemplatesFetcher = new EmailTemplatesFetcher <DealsEmailModel>(new TemplateService(new TemplateBlobStoreClient(storageAccount)), MockTemplatesIdentifier);

            this.contentCreator = new EmailContentCreator <DealsEmailModel>(dealsSelector, null, mockModelContentCreator);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EmailContentCreatorFactory"/> class.
        /// </summary>
        /// <param name="dealsServerBaseAddress">
        /// The deals server base address.
        /// </param>
        public EmailContentCreatorFactory(Uri dealsServerBaseAddress)
        {
            DailyDealsTemplateCreator mockModelContentCreator = new DailyDealsTemplateCreator();
            DealsClient    dealsClient   = new DealsClient(dealsServerBaseAddress, ClientName);
            IDealsSelector dealsSelector = new NaiveDealsSelector(dealsClient);
            IEmailRenderingClient <DailyDealsContract> renderingClient = new EmailRenderingClient();

            this.contentCreator = new EmailContentCreator <DailyDealsContract>(dealsSelector, renderingClient, mockModelContentCreator);
        }
            public void DeleteDealProduct()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                client.DeleteDealProduct(1, 22);

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "deals/1/products/22"));
            }
            public void DeletesCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                client.DeleteParticipant(123, 456);

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "deals/123/participants/456"));
            }
        /// <summary>
        /// Initializes a new instance of the <see cref="TransactionJobProcessor"/> class.
        /// </summary>
        /// <param name="agentId">
        /// The agent id.
        /// </param>
        /// <param name="jobsQueue">
        /// The jobs queue.
        /// </param>
        public TransactionJobProcessor(string agentId, PartnerTransactionsQueue jobsQueue)
        {
            this._agentId   = agentId;
            this._jobsQueue = jobsQueue;
            Uri dealsServerBaseAddress = new Uri(CloudConfigurationManager.GetSetting(DealsServerAddressSetting));

            _dealsClient = new DealsClient(dealsServerBaseAddress, ClientName);
            InitializePartnerToReporter();
        }
            public void DeletesCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                client.DeleteFollower(1, 461);

                connection.Received().Delete(Arg.Is <Uri>(u => u.ToString() == "deals/1/followers/461"));
            }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                client.AddFollower(1, 2);

                connection.Received().Post <DealFollower>(Arg.Is <Uri>(u => u.ToString() == "deals/1/followers"),
                                                          Arg.Is <object>(o => o.ToString() == new { user_id = 2 }.ToString()));
            }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                client.AddParticipant(1, 2);

                // TODO: check the parameter
                connection.Received().Post <DealParticipant>(Arg.Is <Uri>(u => u.ToString() == "deals/1/participants"),
                                                             Arg.Any <object>());
            }
            public void UpdateDealProduct()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var dealProductUpdate = new DealProductUpdate();

                client.UpdateDealProduct(1, 2, dealProductUpdate);

                connection.Received().Put <UpdatedDealProduct>(Arg.Is <Uri>(u => u.ToString() == "deals/1/products/2"),
                                                               Arg.Is(dealProductUpdate));
            }
            public void AddProductToDeal()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var newDealProduct = new NewDealProduct(2, 10, 44);

                client.AddProductToDeal(1, newDealProduct);

                connection.Received().Post <CreatedDealProduct>(Arg.Is <Uri>(u => u.ToString() == "deals/1/products"),
                                                                Arg.Is(newDealProduct));
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                await client.Get(123);

                Received.InOrder(async() =>
                {
                    await connection.Get <Deal>(Arg.Is <Uri>(u => u.ToString() == "deals/123"));
                });
            }
        public void Initialize()
        {
            string storageSetting = CloudConfigurationManager.GetSetting(StorageSetting);

            userHistoryStorage       = new UserHistoryStorage(storageSetting);
            windowsBetweenUserEmails = TimeSpan.Parse(CloudConfigurationManager.GetSetting(WindowBetweenUserEmails));
            mailHistoryLookback      = int.Parse(CloudConfigurationManager.GetSetting(MailHistoryLookBackSetting));
            templateModelCreator     = new DealsTemplateCreator();
            Uri         dealsServerBaseAddress = new Uri(CloudConfigurationManager.GetSetting(DealsServerAddressSetting));
            DealsClient dealsClient            = new DealsClient(dealsServerBaseAddress, ClientName);

            dealsSelector = new NaiveDealsSelector(dealsClient);
        }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                await client.GetByName("name");

                Received.InOrder(async() =>
                {
                    await connection.GetAll <SimpleDeal>(Arg.Is <Uri>(u => u.ToString() == "deals/find"),
                                                         Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                                                               d["term"] == "name"));
                });
            }
            public async Task RequestsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                await client.GetFollowers(123);

                Received.InOrder(async() =>
                {
                    await connection.GetAll <DealFollower>(
                        Arg.Is <Uri>(u => u.ToString() == "deals/123/followers"),
                        Arg.Is <Dictionary <string, string> >(d => d.Count == 1 &&
                                                              d["id"] == "123"));
                });
            }
            public void PostsToTheCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var newDeal      = new NewDeal("title");
                var customFields = new Dictionary <string, ICustomField>()
                {
                    { "5913c8efdcf5c641a516d1fbd498235544b1b195", new LongCustomField(123) }
                };

                newDeal.CustomFields = customFields;
                client.Create(newDeal);

                connection.Received().Post <Deal>(Arg.Is <Uri>(u => u.ToString() == "deals"),
                                                  Arg.Is <NewDeal>(d => d.Title == "title" && d.CustomFields == customFields));
            }
            public void PutsCorrectUrl()
            {
                var connection = Substitute.For <IApiConnection>();
                var client     = new DealsClient(connection);

                var customFields = new Dictionary <string, ICustomField>()
                {
                    { "5913c8efdcf5c641a516d1fbd498235544b1b195", new LongCustomField(123) }
                };
                var editDeal = new DealUpdate {
                    Title = "title", CustomFields = customFields
                };

                client.Edit(123, editDeal);

                connection.Received().Put <Deal>(Arg.Is <Uri>(u => u.ToString() == "deals/123"),
                                                 Arg.Is <DealUpdate>(d => d.Title == "title" && d.CustomFields == customFields));
            }
            public async Task EnsuresNonNullArguments()
            {
                var client = new DealsClient(Substitute.For <IApiConnection>());

                await Assert.ThrowsAsync <ArgumentNullException>(() => client.GetAllForCurrent(null));
            }
        /// <summary>
        /// Constructor
        /// </summary>
        public MerchantReportTemplateCreator()
        {
            Uri dealsServerBaseAddress = new Uri(CloudConfigurationManager.GetSetting(DealsServerAddressSetting));

            _dealsClient = new DealsClient(dealsServerBaseAddress, ClientName);
        }