Exemplo n.º 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);
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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(""));
        }
Exemplo n.º 5
0
        private static Mock <FolderTeamCollection> SetupMockTcForBookStatus(TeamCollectionApiBuilder apiBuilder)
        {
            var mockTeamCollection = new Mock <Bloom.TeamCollection.FolderTeamCollection>();

            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.CurrentCollectionEvenIfDisconnected)
            .Returns(mockTeamCollection.Object);
            apiBuilder.MockTeamCollectionManager.SetupGet(x => x.CurrentCollection).Returns(mockTeamCollection.Object);
            mockTeamCollection.Setup(x => x.GetPathToBookFileInRepo(It.IsAny <string>())).Returns("some fake path");
            mockTeamCollection.Setup(x => x.HasLocalChangesThatMustBeClobbered(It.IsAny <string>())).Returns(false);
            mockTeamCollection.Setup(x => x.HasBeenChangedRemotely(It.IsAny <string>())).Returns(false);
            mockTeamCollection.Setup(x => x.GetCouldNotOpenCorruptZipMessage()).Returns("some fake message");
            return(mockTeamCollection);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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"));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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"));
        }
Exemplo n.º 10
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"));
        }
Exemplo n.º 11
0
        public void HandleCurrentBookStatus_InsufficientRegistration_RequestFails()
        {
            var originalValue = SIL.Windows.Forms.Registration.Registration.Default.Email;

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

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

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

                Assert.Throws(typeof(System.Net.WebException), systemUnderTest);
            }
            finally
            {
                SIL.Windows.Forms.Registration.Registration.Default.Email = originalValue;
            }
        }