private static void GetInboxMessagesExample(EsendexCredentials credentials, MessageBodyService messageBodyService)
        {
            var inboxService = new InboxService(credentials);

            try
            {
                var collection = inboxService.GetMessages(_accountReference, PageIndex, PageSize);

                foreach (var item in collection.Messages)
                {
                    if (messageBodyService != null)
                    {
                        messageBodyService.LoadBodyText(item.Body);
                        Console.WriteLine("\tMessage Id:{0}\tSummary:{1}\n\tBody:{2}\n",
                                          item.Id,
                                          item.Summary,
                                          item.Body.BodyText);
                    }
                    else
                    {
                        Console.WriteLine("\tMessage Id:{0}\tSummary:{1}",
                                          item.Id,
                                          item.Summary);
                    }
                }
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }
        }
Пример #2
0
        public void GetInbox()
        {
            var request  = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
            var articles = InboxService.GetInboxAsync(request, "inbox_a").GetAwaiter().GetResult();

            Assert.IsNotNull(articles);
        }
        public void TestInitialize()
        {
            mockSerialiser = new Mock <ISerialiser>();
            mockRestClient = new Mock <IRestClient>();

            service = new InboxService(mockRestClient.Object, mockSerialiser.Object);
        }
Пример #4
0
        public void TestInitialize()
        {
            mocks = new MockFactory(MockBehavior.Strict);

            mockSerialiser = mocks.Create <ISerialiser>();
            mockRestClient = mocks.Create <IRestClient>();

            service = new InboxService(mockRestClient.Object, mockSerialiser.Object);
        }
Пример #5
0
        public void GetInbox()
        {
            var request  = new FortnoxApiRequest(this.connectionSettings.AccessToken, this.connectionSettings.ClientSecret);
            var articles = InboxService.GetInboxAsync(request, "inbox_d").GetAwaiter().GetResult();

            Assert.IsNotNull(articles);
            Assert.AreEqual(articles.Folder.Files.First().Name, "WebSocket Fortnox API.pdf");
            Assert.AreEqual(articles.Folder.Files.First().Size, 101902);
        }
Пример #6
0
        public async void GetById4ReturnsNull()
        {
            await using (var inbox = new InboxService(MakeInMemoryContext()))
            {
                // Act
                var item = await inbox.GetById(4);

                // Assert
                Assert.Null(item);
            }
        }
Пример #7
0
        protected async Task <string> CreateInboxFile(string inboxFolder)
        {
            var tempFile  = CreateTempFile(out var tempFileName);
            var fileBytes = await File.ReadAllBytesAsync(tempFile);

            File.Delete(tempFile);

            var request  = new FortnoxApiRequest(connectionSettings.AccessToken, connectionSettings.ClientSecret);
            var response = await InboxService.UploadFileAsync(request, inboxFolder, tempFileName, fileBytes);

            return(response.Id);
        }
Пример #8
0
        public void DefaultConstructor()
        {
            // Arrange
            EsendexCredentials credentials = new EsendexCredentials("username", "password");

            // Act
            InboxService serviceInstance = new InboxService(credentials);

            // Assert
            Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>());
            Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>());
        }
Пример #9
0
        public async Task GetAllMessagesWorksCorrect()
        {
            // Arrange
            var db      = DatabaseInitializer.InitializeForInboxService();
            var service = new InboxService(db);

            // Act

            var result = await service.GetAllMessages("georgi", 1);

            //Assert
            result.Messages.Should().NotBeNull();
        }
Пример #10
0
        public async void GetById2ReturnsSecondInbox()
        {
            await using (var inbox = new InboxService(MakeInMemoryContext()))
            {
                // Act
                var item = await inbox.GetById(2);

                // Assert
                Assert.NotNull(item);
                Assert.Equal(2, item.Id);
                Assert.Equal("Do second", item.Value);
            }
        }
Пример #11
0
        public async Task DeleteMessageWorksCorrectlyIfDataIsRight()
        {
            // Arrange
            var db      = DatabaseInitializer.InitializeForInboxService();
            var service = new InboxService(db);

            // Act

            var result = await service.DeleteMessage("georgi", 1);

            //Assert
            result.Should().Be(true);
        }
Пример #12
0
        public async Task DeleteMessageReturnFalseNotExceptionIfDataIsWrong()
        {
            // Arrange
            var db      = DatabaseInitializer.InitializeForInboxService();
            var service = new InboxService(db);

            // Act

            var result = await service.DeleteMessage("georgi", 10);

            //Assert
            result.Should().Be(false);
        }
Пример #13
0
        public async Task GetsTheWriteMessageIfDataIsCorrect()
        {
            // Arrange
            var db      = DatabaseInitializer.InitializeForInboxService();
            var service = new InboxService(db);

            // Act

            var result = await service.GetSingleMessage("georgi", 1);

            //Assert
            result.Should().NotBeNull(result.Title);
        }
Пример #14
0
        public async Task NumberOfPagesGivesCorrectNumber()
        {
            // Arrange
            var db      = DatabaseInitializer.InitializeForInboxService();
            var service = new InboxService(db);

            // Act

            var result = await service.GetAllMessages("kolio", 1);

            //Assert
            result.NumberOfPages.Should().Be(1);
        }
Пример #15
0
        public async void GetAllReturnsAllInboxes()
        {
            await using (var inbox = new InboxService(MakeInMemoryContext()))
            {
                // Act
                var inboxes = await inbox.GetAll();

                // Assert
                Assert.Collection(inboxes,
                                  item => Assert.Equal(1, item.Id),
                                  item => Assert.Equal(2, item.Id));
            }
        }
Пример #16
0
        void NewInboxWithLeadingTrailing()
        {
            InboxService inboxService = new InboxService(db.Object, null);

            var newInbox = inboxService.GetInboxByPath(inboxService.TokenizeString("/one/two/", new Dictionary <string, string>()));

            Assert.Equal("two", newInbox.Name);
            Assert.NotNull(newInbox.ParentInbox);

            Assert.Equal("one", newInbox.ParentInbox.Name);
            Assert.Null(newInbox.ParentInbox.ParentInbox);
            Assert.Contains(newInbox, newInbox.ParentInbox.Children);
        }
Пример #17
0
        public void DefaultDIConstructor()
        {
            // Arrange
            Uri uri = new Uri("http://tempuri.org");
            EsendexCredentials  credentials        = new EsendexCredentials("username", "password");
            IHttpRequestHelper  httpRequestHelper  = new HttpRequestHelper();
            IHttpResponseHelper httpResponseHelper = new HttpResponseHelper();
            IHttpClient         httpClient         = new HttpClient(credentials, uri, httpRequestHelper, httpResponseHelper);

            IRestClient restClient = new RestClient(httpClient);
            ISerialiser serialiser = new XmlSerialiser();

            // Act
            InboxService serviceInstance = new InboxService(restClient, serialiser);

            // Assert
            Assert.That(serviceInstance.RestClient, Is.InstanceOf <RestClient>());
            Assert.That(serviceInstance.Serialiser, Is.InstanceOf <XmlSerialiser>());
        }
Пример #18
0
        void NewInboxUnderExisting()
        {
            InboxService inboxService = new InboxService(db.Object, null);

            Inbox existing = new Inbox()
            {
                Name = "existing",
                Id   = Guid.NewGuid()
            };

            db.Object.Inboxes.Add(existing);

            var newInbox = inboxService.GetInboxByPath(inboxService.TokenizeString("existing/new", new Dictionary <string, string>()));

            Assert.Equal("new", newInbox.Name);
            Assert.NotNull(newInbox.ParentInbox);

            Assert.Equal(existing.Id, newInbox.ParentInbox.Id);
        }
Пример #19
0
        public async void CreateAddsInbox3()
        {
            await using (var inbox = new InboxService(MakeInMemoryContext()))
            {
                // Arrange
                var item = new Inbox()
                {
                    Value = "Do third"
                };

                // Act
                item = await inbox.Create(item);

                // Assert
                Assert.NotNull(item);
                Assert.Equal(3, item.Id);
                Assert.Equal("Do third", item.Value);
                Assert.True(IsAboutNow(item.CreatedAt));
                Assert.True(IsAboutNow(item.UpdatedAt));
            }
        }
Пример #20
0
        private static void GetInboxMessagesExample()
        {
            int pageNumber = 1;
            int pageSize   = 15;

            InboxService inboxService = new InboxService(Credentials);

            try
            {
                InboxMessageCollection collection = inboxService.GetMessages(pageNumber, pageSize);

                foreach (InboxMessage item in collection.Messages)
                {
                    Console.WriteLine("Message Id:{0}\nMessage:{1}\n\n", item.Id, item.Summary);
                }
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
            }
        }
Пример #21
0
        void NewMultiDepthInbox()
        {
            InboxService inboxService = new InboxService(db.Object, null);

            var variables = new Dictionary <string, string>()
            {
                { "SPECIAL/_VARIABLE", "special/value" }
            };

            var newInbox = inboxService.GetInboxByPath(inboxService.TokenizeString("first/[SPECIAL/_VARIABLE]/last", variables));

            Assert.Equal("last", newInbox.Name);
            Assert.NotNull(newInbox.ParentInbox);

            Assert.Equal("special/value", newInbox.ParentInbox.Name);
            Assert.NotNull(newInbox.ParentInbox.ParentInbox);
            Assert.Contains(newInbox, newInbox.ParentInbox.Children);

            Assert.Equal("first", newInbox.ParentInbox.ParentInbox.Name);
            Assert.Null(newInbox.ParentInbox.ParentInbox.ParentInbox);
            Assert.Contains(newInbox.ParentInbox, newInbox.ParentInbox.ParentInbox.Children);
        }
Пример #22
0
        public async void CreateIgnoresEverythingExceptValue()
        {
            await using (var inbox = new InboxService(MakeInMemoryContext()))
            {
                // Arrange
                var item = new Inbox()
                {
                    Id        = 1,
                    Value     = "Do third",
                    CreatedAt = DateTime.Today.AddDays(-2),
                    UpdatedAt = DateTime.Today.AddDays(-1)
                };

                // Act
                item = await inbox.Create(item);

                // Assert
                Assert.NotNull(item);
                Assert.Equal(3, item.Id);
                Assert.Equal("Do third", item.Value);
                Assert.True(IsAboutNow(item.CreatedAt));
                Assert.True(IsAboutNow(item.UpdatedAt));
            }
        }
 /// <inheritdoc />
 public ReceiversController(InboxService inboxService)
 {
     _inboxService = inboxService;
 }
 /// <inheritdoc />
 public RolesController(InboxService inboxService)
 {
     _inboxService = inboxService;
 }