コード例 #1
0
        public void HandleGetLog_NonZeroMessages_MessagesReturned()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            var mockMessageLog = new Mock <ITeamCollectionMessageLog>();

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.MessageLog).Returns(mockMessageLog.Object);
            mockMessageLog.Setup(x => x.GetProgressMessages()).Returns(
                new BloomWebSocketProgressEvent[]
            {
                new BloomWebSocketProgressEvent("unused", ProgressKind.Progress, "1"),
                new BloomWebSocketProgressEvent("unused", ProgressKind.Progress, "2")
            }
                );

            // System Under Test
            var result = ApiTest.GetString(_server, endPoint: "teamCollection/getLog", returnType: ApiTest.ContentType.JSON);

            // Verification
            var deserializedArray = JsonConvert.DeserializeObject <BloomWebSocketProgressEvent[]>(result);
            var messages          = deserializedArray.Select(x => x.message).ToArray();

            CollectionAssert.AreEqual(new string[] { "1", "2" }, messages);
        }
コード例 #2
0
        public void HandleCurrentBookStatus_LockedByFakeUser_FakeUserConvertedToCurrentUser()
        {
            var originalValue = SIL.Windows.Forms.Registration.Registration.Default.Email;

            try
            {
                SIL.Windows.Forms.Registration.Registration.Default.Email = "*****@*****.**";

                var mockBook = new Mock <Bloom.Book.Book>();
                mockBook.Setup(m => m.IsSaveable).Returns(true);
                mockBook.Setup(m => m.FolderPath).Returns("");
                var mockBookSelection = new Mock <BookSelection>();
                mockBookSelection.Setup(m => m.CurrentSelection).Returns(mockBook.Object);

                var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks(true).
                                 WithBookSelection(mockBookSelection.Object);
                var api = apiBuilder.Build();
                api.RegisterWithApiHandler(_server.ApiHandler);

                var mockTeamCollection = SetupMockTcForBookStatus(apiBuilder);
                mockTeamCollection.Setup(x => x.WhoHasBookLocked(It.IsAny <string>())).Returns("this user");
                mockTeamCollection.Setup(x => x.WhatComputerHasBookLocked(It.IsAny <string>())).Returns("My Computer");

                // System Under Test
                var result = ApiTest.GetString(_server, endPoint: "teamCollection/selectedBookStatus", returnType: ApiTest.ContentType.Text);

                // Verification
                StringAssert.Contains("\"who\":\"[email protected]\"", result);
            }
            finally
            {
                // Cleanup
                SIL.Windows.Forms.Registration.Registration.Default.Email = originalValue;
            }
        }
コード例 #3
0
        public void HandleCurrentBookStatus_LockedByRealUser_StatusIndicatesThatuser()
        {
            var originalValue = SIL.Windows.Forms.Registration.Registration.Default.Email;

            try
            {
                SIL.Windows.Forms.Registration.Registration.Default.Email = "*****@*****.**";

                var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks(true);
                var api        = apiBuilder.Build();
                api.RegisterWithApiHandler(_server.ApiHandler);

                var mockTeamCollection = SetupMockTcForBookStatus(apiBuilder);
                mockTeamCollection.Setup(x => x.WhoHasBookLocked(It.IsAny <string>())).Returns("*****@*****.**");
                mockTeamCollection.Setup(x => x.WhatComputerHasBookLocked(It.IsAny <string>())).Returns("Other's Computer");

                // System Under Test
                var result = ApiTest.GetString(_server, endPoint: "teamCollection/selectedBookStatus", returnType: ApiTest.ContentType.Text);

                // Verification
                StringAssert.Contains("\"who\":\"[email protected]\"", result);
            }
            finally
            {
                // Cleanup
                SIL.Windows.Forms.Registration.Registration.Default.Email = originalValue;
            }
        }
コード例 #4
0
        public void HandleRepoFolderPath_NullCurrCollection_ReturnsEmptyString()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            // System Under Test
            var result = ApiTest.GetString(_server, endPoint: "teamCollection/repoFolderPath", returnType: ApiTest.ContentType.Text);

            Assert.That(result, Is.EqualTo(""));
        }
コード例 #5
0
        public void HandleIsTeamCollectionEnabled_ExceptionThrown_RequestFailed()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.CurrentCollectionEvenIfDisconnected).Returns(() => throw new ApplicationException());

            // System Under Test
            TestDelegate systemUnderTest = () => ApiTest.GetString(_server, endPoint: "teamCollection/isTeamCollectionEnabled", returnType: ApiTest.ContentType.Text);

            Assert.Throws(typeof(System.Net.WebException), systemUnderTest);
        }
コード例 #6
0
        public void HandleIsTeamCollectionEnabled_NoCollection_ReturnsFalse()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            // apiBuilder.MockTeamCollectionManager.Object.CurrentCollectionEvenIfDisconnected hasn't been changed,
            // so it will return null

            // System Under Test
            var result = ApiTest.GetString(_server, endPoint: "teamCollection/isTeamCollectionEnabled", returnType: ApiTest.ContentType.Text);

            Assert.That(result, Is.EqualTo("false"));
        }
コード例 #7
0
        public void HandleGetLog_NullMessageLog_RequestFailed()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.MessageLog).Returns((ITeamCollectionMessageLog)null);

            TestDelegate systemUnderTest = () =>
            {
                ApiTest.GetString(_server, endPoint: "teamCollection/getLog", returnType: ApiTest.ContentType.JSON);
            };

            Assert.Throws(typeof(System.Net.WebException), systemUnderTest);
        }
コード例 #8
0
        public void HandleRepoFolderPath_NonNullCurrCollection_ReturnsRepoDescription()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            var mockTeamCollection = new Mock <Bloom.TeamCollection.TeamCollection>();

            mockTeamCollection.SetupGet(x => x.RepoDescription).Returns("Fake Description");

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.CurrentCollectionEvenIfDisconnected).Returns(mockTeamCollection.Object);

            // System Under Test
            var result = ApiTest.GetString(_server, endPoint: "teamCollection/repoFolderPath", returnType: ApiTest.ContentType.Text);

            Assert.That(result, Is.EqualTo("Fake Description"));
        }
コード例 #9
0
        public void HandleIsTeamCollectionEnabled_CurrentSelectionNull_ReturnsTrue()
        {
            var apiBuilder = new TeamCollectionApiBuilder().WithDefaultMocks();
            var api        = apiBuilder.Build();

            api.RegisterWithApiHandler(_server.ApiHandler);

            var mockTeamCollection = new Mock <Bloom.TeamCollection.TeamCollection>();

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.CurrentCollectionEvenIfDisconnected).Returns(mockTeamCollection.Object);

            // apiBuilder.MockBookSelection.Object.CurrentSelection will return null

            // System Under Test
            var result = ApiTest.GetString(_server, endPoint: "teamCollection/isTeamCollectionEnabled", returnType: ApiTest.ContentType.Text);

            Assert.That(result, Is.EqualTo("true"));
        }