Exemple #1
0
        public void Setup()
        {
            this.appConfig = new AppConfig();
            this.authenticationProvider = new MockAuthenticationProvider();
            this.authenticationProvider.Setup(provider => provider.AppendAuthHeaderAsync(It.IsAny <HttpRequestMessage>())).Returns(Task.FromResult(0));
            this.credentialCache     = new MockCredentialCache();
            this.serializer          = new MockSerializer();
            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.serviceInfo         = new ServiceInfo
            {
                AuthenticationProvider = this.authenticationProvider.Object,
            };

            this.serviceInfoProvider = new MockServiceInfoProvider(this.serviceInfo);
            this.webUi          = new MockWebUi();
            this.oneDriveClient = new OneDriveClient(
                this.appConfig,
                this.credentialCache.Object,
                this.httpProvider.Object,
                this.serviceInfoProvider.Object)
            {
                BaseUrl     = Constants.Authentication.OneDriveConsumerBaseUrl,
                ServiceInfo = this.serviceInfo,
            };
        }
        public async Task Setup()
        {
            var transportSerializer = new MockSerializer();
            var pipeName            = Guid.NewGuid().ToString();

            var pipeServer = new IsolatedProcessServerStream(new NamedPipeServerStream(pipeName,
                                                                                       PipeDirection.InOut,
                                                                                       1,
                                                                                       PipeTransmissionMode.Byte,
                                                                                       PipeOptions.Asynchronous));

            var pipeClient =
                new IsolatedProcessClientStream(new NamedPipeClientStream(".",
                                                                          pipeName,
                                                                          PipeDirection.InOut,
                                                                          PipeOptions.Asynchronous));

            _clientChannel = new IsolatedProcessChannel <string>(pipeClient, transportSerializer);
            _serverChannel = new IsolatedProcessChannel <string>(pipeServer, transportSerializer);

            var serverStart = _serverChannel.StartAsync();

            await _clientChannel.StartAsync();

            await serverStart;
        }
        public void Setup()
        {
            this.appConfig = new AppConfig();
            this.authenticationProvider = new MockAuthenticationProvider();
            this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession()));
            this.authenticationProvider.Setup(provider => provider.AppendAuthHeaderAsync(It.IsAny<HttpRequestMessage>())).Returns(Task.FromResult(0));
            this.credentialCache = new MockCredentialCache();
            this.serializer = new MockSerializer();
            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.serviceInfo = new ServiceInfo
            {
                AuthenticationProvider = this.authenticationProvider.Object,
            };

            this.serviceInfoProvider = new MockServiceInfoProvider(this.serviceInfo);
            this.webUi = new MockWebAuthenticationUi();
            this.oneDriveClient = new OneDriveClient(
                this.appConfig,
                this.credentialCache.Object,
                this.httpProvider.Object,
                this.serviceInfoProvider.Object)
            {
                BaseUrl = string.Format(Constants.Authentication.OneDriveConsumerBaseUrlFormatString, "v1.0"),
                ServiceInfo = this.serviceInfo,
            };
        }
Exemple #4
0
        public async Task GetAccountSessionAsync_SingleSignOn()
        {
            const string code  = "code";
            const string token = "token";

            var applicationCallbackUrl = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();

            this.signOut = false;

            this.webAuthenticationUi.responseValues = new Dictionary <string, string> {
                { OAuthConstants.CodeKeyName, code }
            };
            this.webAuthenticationUi.OnAuthenticateAsync = (Uri requestUri, Uri callbackUri) =>
            {
                Assert.IsTrue(requestUri.ToString().Contains("response_type=code"), "Unexpected request Uri.");
                Assert.IsTrue(callbackUri.ToString().Equals(applicationCallbackUrl), "Unexpected callback Uri.");
            };

            using (var httpResponseMessage = new HttpResponseMessage())
                using (var responseStream = new MemoryStream())
                    using (var streamContent = new StreamContent(responseStream))
                    {
                        httpResponseMessage.Content = streamContent;

                        var mockSerializer = new MockSerializer();

                        mockSerializer.OnDeserializeObjectStream = (Stream stream) =>
                        {
                            mockSerializer.DeserializeObjectResponse = new Dictionary <string, string> {
                                { OAuthConstants.AccessTokenKeyName, token }
                            };
                        };

                        var httpProvider = new MockHttpProvider(httpResponseMessage, mockSerializer)
                        {
                            OnSendAsync = (HttpRequestMessage requestMessage) =>
                            {
                                Assert.IsTrue(
                                    requestMessage.RequestUri.ToString().Equals(OAuthConstants.MicrosoftAccountTokenServiceUrl),
                                    "Unexpected token request URL.");
                            }
                        };

                        this.authenticationProvider = new MsaAuthenticationProvider(
                            this.clientId,
                            /* returnUrl */ null,
                            this.scopes,
                            this.credentialCache);

                        this.authenticationProvider.webAuthenticationUi = this.webAuthenticationUi;

                        await this.authenticationProvider.AuthenticateUserAsync(httpProvider).ConfigureAwait(false);

                        Assert.IsNotNull(this.authenticationProvider.CurrentAccountSession, "No account session returned.");
                        Assert.AreEqual(token, this.authenticationProvider.CurrentAccountSession.AccessToken, "Unexpected token returned.");
                    }
        }
        public void Setup()
        {
            this.credentialCache     = new MockAdalCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.serializer          = new MockSerializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer);

            this.authenticationProvider = new MockAuthenticationProvider(new AccountSession());
        }
        public void Setup()
        {
            this.credentialCache     = new MockAdalCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.serializer          = new MockSerializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.authenticationProvider = new MockAuthenticationProvider();
            this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession()));
        }
Exemple #7
0
        public virtual void Setup()
        {
            this.httpResponseMessage = new HttpResponseMessage();
            this.credentialCache     = new MockCredentialCache();
            this.serializer          = new MockSerializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.webAuthenticationUi = new MockWebAuthenticationUi();

            this.oAuthHelper = new OAuthHelper();
        }
        public void Setup()
        {
            this.credentialCache = new MockAdalCredentialCache();
            this.httpResponseMessage = new HttpResponseMessage();
            this.serializer = new MockSerializer();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.authenticationProvider = new MockAuthenticationProvider();
            this.authenticationProvider.Setup(provider => provider.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession()));
        }
Exemple #9
0
        public RequestTestBase()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();
            this.httpResponseMessage    = new HttpResponseMessage();
            this.httpProvider           = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.graphServiceClient = new GraphServiceClient(
                this.authenticationProvider.Object,
                this.httpProvider.Object);
        }
Exemple #10
0
        public SimpleHttpProviderTests()
        {
            this.testHttpMessageHandler = new TestHttpMessageHandler();
            this.authProvider           = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();

            var defaultHandlers = GraphClientFactory.CreateDefaultHandlers(authProvider.Object);
            var httpClient      = GraphClientFactory.Create(handlers: defaultHandlers, finalHandler: testHttpMessageHandler);

            this.simpleHttpProvider = new SimpleHttpProvider(httpClient, this.serializer.Object);
        }
Exemple #11
0
        public void AddWithExistingSerializerForSameType()
        {
            var storage = new ObjectSerializerStorage();

            var serializer = new MockSerializer(typeof(MockDerived));

            storage.Add(serializer);

            var otherSerializer = new MockSerializer(typeof(MockDerived));

            Assert.Throws <DuplicateObjectSerializerException>(() => storage.Add(otherSerializer));
        }
Exemple #12
0
        public void Setup()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();
            this.httpResponseMessage    = new HttpResponseMessage();
            this.httpProvider           = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.oneDriveClient = new OneDriveClient(
                "https://api.onedrive.com/v1.0",
                this.authenticationProvider.Object,
                this.httpProvider.Object);
        }
        public void Setup()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();
            this.httpResponseMessage    = new HttpResponseMessage();
            this.httpProvider           = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.baseClient = new BaseClient(
                this.baseUrl,
                this.authenticationProvider.Object,
                this.httpProvider.Object);
        }
Exemple #14
0
        public void Sets_Address_Of_New_node()
        {
            var node = new Node <int>(2);

            node.ChildrenAddresses.Added.Add(1); // to make dirty
            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 1, 2, 3 };

            _persistence.Persist(node, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());
            Assert.AreEqual(_inMemoryRecordManager._records.Keys.First(), node.Address);
        }
        public void Setup()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer = new MockSerializer();
            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.oneDriveClient = new OneDriveClient(
                "https://api.onedrive.com/v1.0",
                this.authenticationProvider.Object,
                this.httpProvider.Object);
        }
        public AsyncMonitorTests()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();

            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.client = new Mock <IBaseClient>(MockBehavior.Strict);
            this.client.SetupAllProperties();
            this.client.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object);

            this.progress = new MockProgress();

            this.asyncMonitor = new AsyncMonitor <DerivedTypeClass>(this.client.Object, AsyncMonitorTests.monitorUrl);
        }
Exemple #17
0
        public void Add()
        {
            var storage = new ObjectSerializerStorage();

            var serializer = new MockSerializer(typeof(MockDerived));

            storage.Add(serializer);

            Assert.IsTrue(storage.HasSerializerFor(typeof(MockDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockMoreDerived)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(MockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockDerived)));
            Assert.AreSame(serializer, storage.SerializerFor(typeof(MockDerived)));
            Assert.AreSame(serializer, storage.SerializerFor(typeof(MockMoreDerived)));
        }
Exemple #18
0
        void CreateParentAndChildNode(out Node <int> parentNode, out Node <int> childNode)
        {
            parentNode = new Node <int>(2);
            childNode  = new Node <int>(2);
            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 1, 2, 3 };

            parentNode.ChildrenAddresses.Add(100000);
            childNode.ChildrenAddresses.Add(100002);

            _persistence.Persist(parentNode, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());
            _persistence.Persist(childNode, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());
            //add the child to the parent
            parentNode.ChildrenAddresses.Add(childNode.Address);
        }
Exemple #19
0
        public void Does_Not_Save_NonDirty_Node()
        {
            var node = new Node <int>(2);

            node.ChildrenAddresses.Added.Add(1); // to make dirty
            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 1, 2, 3 };
            _persistence.Persist(node, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());

            node.ClearChanges();
            serializer.SerializeFunc = (obj) => new byte[] { 4, 5, 6 };
            _persistence.Persist(node, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());

            Assert.AreEqual(new byte[] { 1, 2, 3 }, _inMemoryRecordManager._records[node.Address].Data);
        }
Exemple #20
0
        public void Updates_A_Node()
        {
            var node = new Node <int>(2);

            node.ChildrenAddresses.Added.Add(1); // to make it dirty
            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 1, 2, 3 };
            _persistence.Persist(node, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());

            node.ChildrenAddresses.Added.Add(2); // to make it dirty again
            serializer.SerializeFunc = (obj) => new byte[] { 4, 5, 6 };
            _persistence.Persist(node, new Dictionary <long, Node <int> >(), serializer, new IndexMetaRecord());

            Assert.AreEqual(new byte[] { 4, 5, 6 }, _inMemoryRecordManager._records.Values.First().Data);
        }
        public virtual void Setup()
        {
            this.httpResponseMessage = new HttpResponseMessage();
            this.credentialCache     = new MockCredentialCache();
            this.serializer          = new MockSerializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.webAuthenticationUi = new MockWebAuthenticationUi();

            this.authenticationProvider = new MsaAuthenticationProvider(
                MsaAuthenticationProviderTests.ClientId,
                MsaAuthenticationProviderTests.ClientSecret,
                MsaAuthenticationProviderTests.ReturnUrl,
                this.scopes,
                this.credentialCache.Object);

            this.authenticationProvider.webAuthenticationUi = this.webAuthenticationUi.Object;
        }
Exemple #22
0
        public async Task GetAccountSessionAsync_ReturnUri()
        {
            const string code  = "code";
            const string token = "token";

            this.serviceInfo.ReturnUrl = "https://login.live.com/returnUrl";
            this.signOut = false;
            this.webAuthenticationUi.responseValues = new Dictionary <string, string> {
                { Constants.Authentication.CodeKeyName, code }
            };
            this.webAuthenticationUi.OnAuthenticateAsync = (Uri requestUri, Uri callbackUri) =>
            {
                Assert.IsTrue(requestUri.ToString().Contains("response_type=code"), "Unexpected request Uri.");
                Assert.IsTrue(callbackUri.ToString().Equals(this.serviceInfo.ReturnUrl), "Unexpected callback Uri.");
            };

            using (var httpResponseMessage = new HttpResponseMessage())
                using (var responseStream = new MemoryStream())
                    using (var streamContent = new StreamContent(responseStream))
                    {
                        httpResponseMessage.Content = streamContent;

                        var mockSerializer = new MockSerializer();

                        mockSerializer.OnDeserializeObjectStream = (Stream stream) =>
                        {
                            mockSerializer.DeserializeObjectResponse = new Dictionary <string, string> {
                                { Constants.Authentication.AccessTokenKeyName, token }
                            };
                        };

                        this.serviceInfo.HttpProvider = new MockHttpProvider(httpResponseMessage, mockSerializer)
                        {
                            OnSendAsync = (HttpRequestMessage requestMessage) =>
                            {
                                Assert.IsTrue(requestMessage.RequestUri.ToString().Equals(this.serviceInfo.TokenServiceUrl), "Unexpected token request URL.");
                            }
                        };

                        var accountSession = await this.authenticationProvider.GetAccountSessionAsync();

                        Assert.IsNotNull(accountSession, "No account session returned.");
                        Assert.AreEqual(token, accountSession.AccessToken, "Unexpected token returned.");
                    }
        }
Exemple #23
0
        public void Setup()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer             = new MockSerializer();

            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.oneDriveClient = new Mock <IOneDriveClient>(MockBehavior.Strict);
            this.oneDriveClient.SetupAllProperties();
            this.oneDriveClient.SetupGet(client => client.AuthenticationProvider).Returns(this.authenticationProvider.Object);
            this.oneDriveClient.Setup(client => client.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession()));
            this.oneDriveClient.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object);

            this.progress = new MockProgress();

            this.asyncMonitor = new ItemCopyAsyncMonitor(this.oneDriveClient.Object, AsyncMonitorTests.monitorUrl);
        }
        public void Setup()
        {
            this.authenticationProvider = new MockAuthenticationProvider();
            this.serializer = new MockSerializer();

            this.httpResponseMessage = new HttpResponseMessage();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);

            this.oneDriveClient = new Mock<IOneDriveClient>(MockBehavior.Strict);
            this.oneDriveClient.SetupAllProperties();
            this.oneDriveClient.SetupGet(client => client.AuthenticationProvider).Returns(this.authenticationProvider.Object);
            this.oneDriveClient.Setup(client => client.AuthenticateAsync()).Returns(Task.FromResult(new AccountSession()));
            this.oneDriveClient.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object);

            this.progress = new MockProgress();
            
            this.asyncMonitor = new ItemCopyAsyncMonitor(this.oneDriveClient.Object, AsyncMonitorTests.monitorUrl);
        }
Exemple #25
0
 public void Setup()
 {
     this.ClientId               = "123456";
     this.ClientSecret           = "QWERTY";
     this.ReturnUrl              = "http://www.returnurl.com";
     this.Scopes                 = new string[] { "Scope1", "Scope2" };
     this.CredentialCache        = new CredentialCache();
     this.Serializer             = new MockSerializer();
     this.ResponseMessage        = new HttpResponseMessage();
     this.HttpProvider           = new MockHttpProvider(this.ResponseMessage, this.Serializer);
     this.WebAuthenticationUi    = new MockWebAuthenticationUi();
     this.AuthenticationProvider = new MsaAuthenticationProvider(
         this.ClientId,
         this.ClientSecret,
         this.ReturnUrl,
         this.Scopes,
         this.CredentialCache,
         this.WebAuthenticationUi);
 }
Exemple #26
0
        public void AddClassSerializerWithMoreDerivedClassSerializersExisting()
        {
            var storage = new ObjectSerializerStorage();

            var derivedSerializer = new MockSerializer(typeof(MockDerived));

            storage.Add(derivedSerializer);

            var baseSerializer = new MockSerializer(typeof(MockBase));

            storage.Add(baseSerializer);

            Assert.IsTrue(storage.HasSerializerFor(typeof(MockDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockMoreDerived)));
            Assert.IsTrue(storage.HasSerializerFor(typeof(MockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockBase)));
            Assert.IsFalse(storage.HasSerializerFor(typeof(IMockDerived)));
            Assert.AreSame(baseSerializer, storage.SerializerFor(typeof(MockBase)));
            Assert.AreSame(derivedSerializer, storage.SerializerFor(typeof(MockDerived)));
            Assert.AreSame(derivedSerializer, storage.SerializerFor(typeof(MockMoreDerived)));
        }
Exemple #27
0
        public void Resets_Dirty_Flags_For_Saved_Nodes()
        {
            Node <int> node;
            Node <int> childNode;

            CreateParentAndChildNode(out node, out childNode);

            var loadedNodes = new Dictionary <long, Node <int> >();

            loadedNodes[node.Address]      = node;
            loadedNodes[childNode.Address] = childNode;

            childNode.ChildrenAddresses.RemoveAt(0); //makes it dirty

            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 4, 5, 6 };
            _persistence.Persist(node, loadedNodes, serializer, new IndexMetaRecord());

            Assert.AreEqual(0, loadedNodes.Values.Where(n => n.Dirty).Count());
        }
Exemple #28
0
        public void Saves_Child_Nodes()
        {
            Node <int> node;
            Node <int> childNode;

            CreateParentAndChildNode(out node, out childNode);

            var loadedNodes = new Dictionary <long, Node <int> >();

            loadedNodes[node.Address]      = node;
            loadedNodes[childNode.Address] = childNode;

            childNode.ChildrenAddresses.RemoveAt(0); //makes it dirty

            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[] { 4, 5, 6 };
            _persistence.Persist(node, loadedNodes, serializer, new IndexMetaRecord());

            Assert.AreEqual(new byte[] { 4, 5, 6 }, _inMemoryRecordManager._records[childNode.Address].Data);
        }
        public virtual void Setup()
        {
            this.httpResponseMessage = new HttpResponseMessage();
            this.credentialCache = new MockCredentialCache();
            this.serializer = new MockSerializer();
            this.httpProvider = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.webUi = new MockWebUi();

            this.serviceInfo = new ServiceInfo
            {
                AppId = "12345",
                AuthenticationServiceUrl = "https://login.live.com/authenticate",
                CredentialCache = this.credentialCache.Object,
                HttpProvider = this.httpProvider.Object,
                ReturnUrl = "https://login.live.com/return",
                Scopes = new string[] { "scope1", "scope2" },
                SignOutUrl = "https://login.live.com/signout",
                TokenServiceUrl = "https://login.live.com/token",
                WebAuthenticationUi = this.webUi.Object
            };
        }
Exemple #30
0
        public virtual void Setup()
        {
            this.httpResponseMessage = new HttpResponseMessage();
            this.credentialCache     = new MockCredentialCache();
            this.serializer          = new MockSerializer();
            this.httpProvider        = new MockHttpProvider(this.httpResponseMessage, this.serializer.Object);
            this.webAuthenticationUi = new MockWebAuthenticationUi();

            this.serviceInfo = new ServiceInfo
            {
                AppId = "12345",
                AuthenticationServiceUrl = "https://login.live.com/authenticate",
                CredentialCache          = this.credentialCache.Object,
                HttpProvider             = this.httpProvider.Object,
                ReturnUrl           = "https://login.live.com/return",
                Scopes              = new string[] { "scope1", "scope2" },
                SignOutUrl          = "https://login.live.com/signout",
                TokenServiceUrl     = "https://login.live.com/token",
                WebAuthenticationUi = this.webAuthenticationUi.Object
            };
        }
Exemple #31
0
        public void Updates_Child_Address_When_Child_Moved()
        {
            Node <int> node;
            Node <int> childNode;

            CreateParentAndChildNode(out node, out childNode);

            var loadedNodes = new Dictionary <long, Node <int> >();

            loadedNodes[node.Address]      = node;
            loadedNodes[childNode.Address] = childNode;


            childNode.ChildrenAddresses.RemoveAt(0); //makes it dirty

            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[1000];
            _persistence.Persist(node, loadedNodes, serializer, new IndexMetaRecord());

            Assert.AreEqual(childNode.Address, node.ChildrenAddresses.Last());
        }
Exemple #32
0
        public void Deletes_Child_Node_When_Not_Reachable()
        {
            Node <int> node;
            Node <int> childNode;

            CreateParentAndChildNode(out node, out childNode);

            var loadedNodes = new Dictionary <long, Node <int> >();

            loadedNodes[node.Address]      = node;
            loadedNodes[childNode.Address] = childNode;

            childNode.ChildrenAddresses.RemoveAt(0);                             //makes it dirty
            node.ChildrenAddresses.RemoveRange(0, node.ChildrenAddresses.Count); //remove any children

            var serializer = new MockSerializer <Node <int> >();

            serializer.SerializeFunc = (obj) => new byte[1000];
            _persistence.Persist(node, loadedNodes, serializer, new IndexMetaRecord());

            Assert.IsFalse(_inMemoryRecordManager._records.ContainsKey(childNode.Address));
        }
Exemple #33
0
        public void BasicTest()
        {
            City testCity1 = new City {
                FullName = "Hello", ShortName = "H", Latitude = 12.3, Longitude = 45.6
            };
            City testCity2 = new City {
                FullName = "World", ShortName = "W", Latitude = 32.1, Longitude = 65.4
            };
            List <City> testCities = new List <City>(new City[] { testCity1, testCity2 });
            Dictionary <City, double> testScores = new Dictionary <City, double>();

            testScores[testCity1] = 0.5;
            testScores[testCity2] = 0.75;
            string testSerialization = "TestResponse";

            MockCityStorage cityStorage = new MockCityStorage
            {
                GetCitiesStartsWithCalledCount = 0,
                GetCitiesStartsWithParameter   = null,
                CitiesToReturn = testCities
            };
            MockScorer scorer = new MockScorer
            {
                GetScoreCalledCount      = 0,
                GetScoreCalledParameters = new List <MockScorer.Parameter>(),
                ScoresToReturn           = testScores
            };
            MockSerializer serializer = new MockSerializer
            {
                SerializeCalledCount  = 0,
                SerializeSuggestions  = null,
                SerializationToReturn = testSerialization
            };

            CityService.CityService cityService = new CityService.CityService(cityStorage, scorer, serializer);

            // test the bad parameters
            string response = cityService.AutoComplete(null, null, null, 0);

            Assert.AreEqual("q not specified", response);
            response = cityService.AutoComplete("hello", -91, null, 0);
            Assert.AreEqual("latitude should be between -90 and 90", response);
            response = cityService.AutoComplete("hello", 91, null, 0);
            Assert.AreEqual("latitude should be between -90 and 90", response);
            response = cityService.AutoComplete("hello", 45, -181, 0);
            Assert.AreEqual("longitude should be between -180 and 180", response);
            response = cityService.AutoComplete("hello", 45, 181, 0);
            Assert.AreEqual("longitude should be between -180 and 180", response);

            // test the general case
            response = cityService.AutoComplete("a", 45, 32, 5);
            Assert.AreEqual(testSerialization, response);
            Assert.AreEqual(1, cityStorage.GetCitiesStartsWithCalledCount);
            Assert.AreEqual("a", cityStorage.GetCitiesStartsWithParameter);
            Assert.AreEqual(2, scorer.GetScoreCalledCount);
            Assert.AreEqual(testCity1, scorer.GetScoreCalledParameters[0].GetScoreCalledCity); // testCity1 is first since this is the order from the cityStorage
            Assert.AreEqual("a", scorer.GetScoreCalledParameters[0].GetScoreCalledName);
            Assert.AreEqual(45, scorer.GetScoreCalledParameters[0].GetScoreCalledLatitude);
            Assert.AreEqual(32, scorer.GetScoreCalledParameters[0].GetScoreCalledLongitude);
            Assert.AreEqual(testCity2, scorer.GetScoreCalledParameters[1].GetScoreCalledCity);
            Assert.AreEqual("a", scorer.GetScoreCalledParameters[1].GetScoreCalledName);
            Assert.AreEqual(45, scorer.GetScoreCalledParameters[1].GetScoreCalledLatitude);
            Assert.AreEqual(32, scorer.GetScoreCalledParameters[1].GetScoreCalledLongitude);
            Assert.AreEqual(1, serializer.SerializeCalledCount);
            Assert.AreEqual(2, serializer.SerializeSuggestions.Count);
            Assert.AreEqual(testCity2.FullName, serializer.SerializeSuggestions[0].Name); // sorted from highest to lower, so testCity2 first
            Assert.AreEqual(testCity2.Latitude.ToString(), serializer.SerializeSuggestions[0].Latitude);
            Assert.AreEqual(testCity2.Longitude.ToString(), serializer.SerializeSuggestions[0].Longitude);
            Assert.AreEqual(testScores[testCity2], serializer.SerializeSuggestions[0].Score);
            Assert.AreEqual(testCity1.FullName, serializer.SerializeSuggestions[1].Name);
            Assert.AreEqual(testCity1.Latitude.ToString(), serializer.SerializeSuggestions[1].Latitude);
            Assert.AreEqual(testCity1.Longitude.ToString(), serializer.SerializeSuggestions[1].Longitude);
            Assert.AreEqual(testScores[testCity1], serializer.SerializeSuggestions[1].Score);

            // reset the mock objects
            cityStorage.GetCitiesStartsWithCalledCount = 0;
            cityStorage.GetCitiesStartsWithParameter   = null;
            scorer.GetScoreCalledCount = 0;
            scorer.GetScoreCalledParameters.Clear();
            serializer.SerializeCalledCount = 0;
            serializer.SerializeSuggestions = null;

            // test the case where the city service might limit results (testCity2 has higher score so that one is kept)
            response = cityService.AutoComplete("a", 45, 32, 1);
            Assert.AreEqual(testSerialization, response);
            Assert.AreEqual(1, cityStorage.GetCitiesStartsWithCalledCount);
            Assert.AreEqual("a", cityStorage.GetCitiesStartsWithParameter);
            Assert.AreEqual(2, scorer.GetScoreCalledCount);
            Assert.AreEqual(testCity1, scorer.GetScoreCalledParameters[0].GetScoreCalledCity); // testCity1 is first since this is the order from the cityStorage
            Assert.AreEqual("a", scorer.GetScoreCalledParameters[0].GetScoreCalledName);
            Assert.AreEqual(45, scorer.GetScoreCalledParameters[0].GetScoreCalledLatitude);
            Assert.AreEqual(32, scorer.GetScoreCalledParameters[0].GetScoreCalledLongitude);
            Assert.AreEqual(testCity2, scorer.GetScoreCalledParameters[1].GetScoreCalledCity);
            Assert.AreEqual("a", scorer.GetScoreCalledParameters[1].GetScoreCalledName);
            Assert.AreEqual(45, scorer.GetScoreCalledParameters[1].GetScoreCalledLatitude);
            Assert.AreEqual(32, scorer.GetScoreCalledParameters[1].GetScoreCalledLongitude);
            Assert.AreEqual(1, serializer.SerializeCalledCount);
            Assert.AreEqual(1, serializer.SerializeSuggestions.Count);
            Assert.AreEqual(testCity2.FullName, serializer.SerializeSuggestions[0].Name); // sorted from highest to lower, so testCity2 is the only one
            Assert.AreEqual(testCity2.Latitude.ToString(), serializer.SerializeSuggestions[0].Latitude);
            Assert.AreEqual(testCity2.Longitude.ToString(), serializer.SerializeSuggestions[0].Longitude);
            Assert.AreEqual(testScores[testCity2], serializer.SerializeSuggestions[0].Score);
        }
        public async Task GetAccountSessionAsync_ReturnUri()
        {
            const string code = "code";
            const string token = "token";

            this.serviceInfo.ReturnUrl = "https://login.live.com/returnUrl";
            this.signOut = false;
            this.webAuthenticationUi.responseValues = new Dictionary<string, string> { { Constants.Authentication.CodeKeyName, code } };
            this.webAuthenticationUi.OnAuthenticateAsync = (Uri requestUri, Uri callbackUri) =>
            {
                Assert.IsTrue(requestUri.ToString().Contains("response_type=code"), "Unexpected request Uri.");
                Assert.IsTrue(callbackUri.ToString().Equals(this.serviceInfo.ReturnUrl), "Unexpected callback Uri.");
            };

            using (var httpResponseMessage = new HttpResponseMessage())
            using (var responseStream = new MemoryStream())
            using (var streamContent = new StreamContent(responseStream))
            {
                httpResponseMessage.Content = streamContent;

                var mockSerializer = new MockSerializer();

                mockSerializer.OnDeserializeObjectStream = (Stream stream) =>
                {
                    mockSerializer.DeserializeObjectResponse = new Dictionary<string, string> { { Constants.Authentication.AccessTokenKeyName, token } };
                };

                this.serviceInfo.HttpProvider = new MockHttpProvider(httpResponseMessage, mockSerializer)
                {
                    OnSendAsync = (HttpRequestMessage requestMessage) =>
                    {
                        Assert.IsTrue(requestMessage.RequestUri.ToString().Equals(this.serviceInfo.TokenServiceUrl), "Unexpected token request URL.");
                    }
                };

                var accountSession = await this.authenticationProvider.GetAccountSessionAsync();

                Assert.IsNotNull(accountSession, "No account session returned.");
                Assert.AreEqual(token, accountSession.AccessToken, "Unexpected token returned.");
            }
        }