Пример #1
0
        public void Find_RequestForFindAccount_FindAccount()
        {
            var accountSettingsStub = new[]
            {
                new AccountSettingsItem()
                {
                    Login = expectedLogin, ServerName = expectedServerName, Token = expectedToken
                },
                new AccountSettingsItem()
                {
                    Login = "******", ServerName = "Tandex", Token = "9875452"
                },
            };

            _mockAccountSettings.SetupGet(settings => settings.LoadAccounts()).Returns(accountSettingsStub);


            _accountRegistry = new AccountRegistry(_mockAccountSettings.Object, _accountContainerStub);

            _accountRegistry.Load();

            IAccountProjection accountFound = _accountRegistry.Find(expectedLogin);

            _mockAccount.VerifySet(acc => acc.Login, expectedLogin, Occurred.Once());
            _mockAccount.VerifySet(acc => acc.Token, expectedToken, Occurred.Once());
            Assert.AreEqual(expectedLogin, accountFound.Login);
            Assert.AreEqual(expectedServerName, accountFound.ServerName);
            Assert.AreEqual(expectedToken, accountFound.Token);
            Assert.IsNotNull(accountFound);
        }
Пример #2
0
        public void Load_RequestForLoadSetting_LoadSettings()
        {
            var accountSettingsStub = new[]
            {
                new AccountSettingsItem()
                {
                    Login = expectedLogin, ServerName = expectedServerName, Token = expectedToken
                },
            };

            _mockAccountSettings.SetupGet(settings => settings.LoadAccounts()).Returns(accountSettingsStub);


            _accountRegistry = new AccountRegistry(_mockAccountSettings.Object, _accountContainerStub);

            _accountRegistry.LoadedEvent += (o, e) =>
            {
                Assert.IsNotNull(e.Accounts);
                Assert.AreEqual(e.Accounts.Length, 1);
                _mockAccount.Verify(acc => acc.LoadConnector(expectedServerName), Occurred.Once());
                _mockAccount.VerifySet(acc => acc.Login, expectedLogin, Occurred.Once());
                _mockAccount.VerifySet(acc => acc.Token, expectedToken, Occurred.Once());
                Assert.AreEqual(e.Size, expectedSize);
            };
            _accountRegistry.Load();
        }
Пример #3
0
        public async Task Update_RequestForUpdate_GetNewInfo()
        {
            _mockService.Setup(fileStorage => fileStorage.Update()).Returns(Task.Run(() => { }));

            await _account.Update();

            _mockService.Verify(fileStorage => fileStorage.Update(), Occurred.Once());
        }
Пример #4
0
        public async Task SignOut_RequestForSignOut_DeleteToken()
        {
            _mockService.Setup(fileStorage => fileStorage.SignOut()).Returns(Task.Run(() => { }));

            await _account.SignOut();

            _mockService.Verify(fileStorage => fileStorage.SignOut(), Occurred.Once());
        }
Пример #5
0
        public async Task SignIn_RequestForSignIn_GetToken()
        {
            string token = "simpleToken";

            _mockService.Setup(fileStorage => fileStorage.SignIn(token)).Returns(Task.Run(() => { }));

            await _account.SignIn(token);

            _mockService.Verify(fileStorage => fileStorage.SignIn(token), Occurred.Once());
        }
Пример #6
0
        public async Task VerifyMatchesExpectedSingleVisitAsync()
        {
            var proxy = Mock.Create <IUserService>();

            proxy.Setup(p => p.DeleteAsync("Homer")).Returns(Task.Delay(0));

            var controller = new UserController(proxy);

            await controller.DeleteAsync("Homer");

            proxy.Verify(p => p.DeleteAsync("Homer"), Occurred.Once());
        }
Пример #7
0
        public void VerifyMatchesExpectedSingleVisit()
        {
            var proxy = Mock.Create <IUserService>();

            proxy.Setup(p => p.Save("Bart")).Returns(true);

            var controller = new UserController(proxy);

            controller.Save("Bart");

            proxy.Verify(p => p.Save("Bart"), Occurred.Once());
        }
Пример #8
0
        public void VerifyMatchesSingleVisitForAnyParameter()
        {
            var proxy = Mock.Create <IUserService>();

            proxy.Setup(p => p.Delete(Param.IsAny <string>()));

            var controller = new UserController(proxy);

            controller.Delete("Homer");

            proxy.Verify(p => p.Delete(Param.IsAny <string>()), Occurred.Once());
        }
Пример #9
0
        public void RaisedEventInvokesAttachedSubjectHandler()
        {
            var proxy = Mock.Create <IThermostatService>();

            proxy.Setup(p => p.SwitchOff());
            // ReSharper disable once UnusedVariable
            var controller = new ThemostatController(proxy);

            proxy.Raise(p => p.Hot += null, new EventArgs());

            proxy.Verify(p => p.SwitchOff(), Occurred.Once());
        }
Пример #10
0
        public void VerifyMatchesExpectedSingleVisit()
        {
            var proxy = Mock.Create <IUserService>();

            proxy.Setup(p => p.Delete("Homer"));

            var controller = new UserController(proxy);

            controller.Delete("Homer");

            proxy.Verify(p => p.Delete("Homer"), Occurred.Once());
        }
Пример #11
0
        public void WriteData_With3_ShouldSave8()
        {
            // Arrange
            var input = 3;

            // Act
            _underTest.WriteData(input);

            // Assert
            var expected = 8;

            _dataStore.Verify(x => x.SaveData(expected), Occurred.Once());
        }
Пример #12
0
        public void RaisedEventPassesParameters()
        {
            const int temp  = 100;
            var       proxy = Mock.Create <IThermostatService>();

            proxy.Setup(p => p.ChangeTemp(temp));
            // ReSharper disable once UnusedVariable
            var controller = new ThemostatController(proxy);

            proxy.Raise(p => p.TempChanged += null, new TempChangedEventArgs(temp));

            proxy.Verify(p => p.ChangeTemp(temp), Occurred.Once());
        }
Пример #13
0
        public void SetActive_RequestForSetActive_SetActiveState()
        {
            GroupSettings _settings    = new GroupSettings(_mockService.Object, _parameterName, null);
            string        stubSettings =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<GroupSettingsContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <Name>Room</Name>\r\n  <IsActive>false</IsActive>\r\n  <Items>\r\n    <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n      <Name>MainContainer</Name>\r\n      <IsActive>true</IsActive>\r\n      <Items>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n          <Name>Group</Name>\r\n          <Items>\r\n            <string>Account1</string>\r\n            <string>Account2</string>\r\n          </Items>\r\n        </GroupSettingsItem>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n          <Name>Container</Name>\r\n          <IsActive>true</IsActive>\r\n          <Items>\r\n            <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n              <Name>Group2</Name>\r\n              <Items>\r\n                <string>Account1</string>\r\n              </Items>\r\n            </GroupSettingsItem>\r\n          </Items>\r\n        </GroupSettingsItem>\r\n      </Items>\r\n    </GroupSettingsItem>\r\n  </Items>\r\n</GroupSettingsContainer>";
            string expectedStringForSave =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<GroupSettingsContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <Name>Room</Name>\r\n  <IsActive>false</IsActive>\r\n  <Items>\r\n    <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n      <Name>MainContainer</Name>\r\n      <IsActive>false</IsActive>\r\n      <Items>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n          <Name>Group</Name>\r\n          <Items>\r\n            <string>Account1</string>\r\n            <string>Account2</string>\r\n          </Items>\r\n        </GroupSettingsItem>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n          <Name>Container</Name>\r\n          <IsActive>true</IsActive>\r\n          <Items>\r\n            <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n              <Name>Group2</Name>\r\n              <Items>\r\n                <string>Account1</string>\r\n              </Items>\r\n            </GroupSettingsItem>\r\n          </Items>\r\n        </GroupSettingsItem>\r\n      </Items>\r\n    </GroupSettingsItem>\r\n  </Items>\r\n</GroupSettingsContainer>";

            _mockService.Setup(settings => settings.GetValueAsString(_parameterName)).Returns(stubSettings);
            GroupSettingsContainer actuality = _settings.LoadGroupTree();

            _settings.SetActive(new List <string>(), "MainContainer", false);

            _mockService.Verify(settings => settings.SetValueAsString(_parameterName, expectedStringForSave),
                                Occurred.Once());
        }
Пример #14
0
        public void Add_RequestForAddContainer_AddNewContainer()
        {
            GroupSettings _settings             = new GroupSettings(_mockService.Object, _parameterName, null);
            string        expectedStringForSave =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<GroupSettingsContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <Name>Room</Name>\r\n  <IsActive>false</IsActive>\r\n  <Items>\r\n    <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n      <Name>MainContainer</Name>\r\n      <IsActive>true</IsActive>\r\n      <Items>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n          <Name>Group</Name>\r\n          <Items>\r\n            <string>Account1</string>\r\n            <string>Account2</string>\r\n          </Items>\r\n        </GroupSettingsItem>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n          <Name>Container</Name>\r\n          <IsActive>true</IsActive>\r\n          <Items />\r\n        </GroupSettingsItem>\r\n      </Items>\r\n    </GroupSettingsItem>\r\n  </Items>\r\n</GroupSettingsContainer>";

            var expected = new GroupSettingsContainer()
            {
                Name  = "MainContainer", IsActive = true,
                Items = new List <GroupSettingsItem>()
                {
                    new GroupSettingsGroup()
                    {
                        Items = new List <string>()
                        {
                            "Account1", "Account2"
                        },
                        Name = "Group"
                    },
                    new GroupSettingsContainer()
                    {
                        Name     = "Container",
                        Items    = new List <GroupSettingsItem>(),
                        IsActive = true
                    }
                }
            };

            _mockService.Setup(settings => settings.GetValueAsString(_parameterName)).Returns(String.Empty);
            GroupSettingsContainer actuality = _settings.LoadGroupTree();

            _settings.Add(new List <string>(), expected);

            _mockService.Verify(settings => settings.SetValueAsString(_parameterName, expectedStringForSave),
                                Occurred.Once());

            Assert.IsNotNull(actuality);
            Assert.IsNotNull(actuality.Items);
        }
        public void SaveOperations_RequestForSaveOperations_SaveOperations()
        {
            List<IBackgroundOperation> backgroundOperations = new List<IBackgroundOperation>();
            Mock<IBackgroundOperation> mock1 = Mock.Create<IBackgroundOperation>();
            Mock<IBackgroundOperation> mock2 = Mock.Create<IBackgroundOperation>();
            _mockAccount.SetupGet(projection => projection.ServerName).Returns("OneDrive");
            _mockRemoteFile.SetupGet(file => file.Account).Returns(_mockAccount.Object);

            mock1.SetupGet(operation => operation.Action).Returns(BackgroundOperationActionEnum.Download);
            mock1.SetupGet(operation => operation.RemoteFile).Returns(_mockRemoteFile.Object);

            mock2.SetupGet(operation => operation.Action).Returns(BackgroundOperationActionEnum.Upload);
            mock2.SetupGet(operation => operation.RemoteFile).Returns(_mockRemoteFile.Object);

            backgroundOperations.Add(mock1.Object);
            backgroundOperations.Add(mock2.Object);

             _dispatcherSettings.SaveOperations(_parameterName, backgroundOperations);
            _mockService.Verify(settings => settings.SetValueAsString(_parameterName, "[{\"Action\":0,\"ServerName\":\"OneDrive\",\"State\":\"generatedProxy_5\"},{\"Action\":1,\"ServerName\":\"OneDrive\",\"State\":\"generatedProxy_5\"}]"),Occurred.Once());
        }
Пример #16
0
        public void SaveSettings_RequestForSaveSettings_SaveSettings()
        {
            var expectedAccountSettings = new[]
            {
                new AccountSettingsItem()
                {
                    Login = expectedLogin, ServerName = expectedServerName, Token = expectedToken
                }
            };

            _mockAccountSettings.SetupGet(settings => settings.LoadAccounts()).Returns(Array.Empty <IAccountSettingsItem>());

            _accountRegistry = new AccountRegistry(_mockAccountSettings.Object, _accountContainerStub);

            _accountRegistry.Registry(_mockAccount.Object);
            _mockAccountSettings.Verify(settings => settings.SaveAccounts(Param.Is <IAccountSettingsItem[]>(items => items.SequenceEqual(expectedAccountSettings))), Occurred.Once());
        }
Пример #17
0
        public void SaveAccounts_RequestForSaveAccount_SaveAccount()
        {
            string expected =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<ArrayOfAccountSettingsItem xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <AccountSettingsItem>\r\n    <Login>myLogin</Login>\r\n    <Token>123</Token>\r\n    <ServerName>Yandex</ServerName>\r\n  </AccountSettingsItem>\r\n</ArrayOfAccountSettingsItem>";

            _settings.SaveAccounts(new[]
            {
                new AccountSettingsItem()
                {
                    Login = "******", ServerName = "Yandex", Token = "123"
                },
            });
            _mockService.Verify(settings => settings.SetValueAsString(_parameterName, expected), Occurred.Once());
        }
Пример #18
0
        public void SaveGroupTree_RequestForSave_Save()
        {
            string expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<GroupSettingsContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <IsActive>false</IsActive>\r\n  <Items>\r\n    <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n      <Name>Container1</Name>\r\n      <IsActive>true</IsActive>\r\n      <Items>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsContainer\">\r\n          <Name>Container2</Name>\r\n          <IsActive>false</IsActive>\r\n        </GroupSettingsItem>\r\n        <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n          <Name>Group2</Name>\r\n        </GroupSettingsItem>\r\n      </Items>\r\n    </GroupSettingsItem>\r\n    <GroupSettingsItem xsi:type=\"GroupSettingsGroup\">\r\n      <Name>Group</Name>\r\n      <Items>\r\n        <string>Account1</string>\r\n      </Items>\r\n    </GroupSettingsItem>\r\n  </Items>\r\n</GroupSettingsContainer>";
            var    forSave  = new GroupSettingsContainer()
            {
                Items = new List <GroupSettingsItem>()
                {
                    new GroupSettingsContainer()
                    {
                        Name  = "Container1",
                        Items = new List <GroupSettingsItem>()
                        {
                            new GroupSettingsContainer()
                            {
                                Name = "Container2"
                            },
                            new GroupSettingsGroup()
                            {
                                Name = "Group2"
                            }
                        },
                        IsActive = true
                    },
                    new GroupSettingsGroup()
                    {
                        Name = "Group", Items = new List <string>()
                        {
                            "Account1"
                        }
                    }
                }
            };
            GroupSettings _settings = new GroupSettings(_mockService.Object, _parameterName, forSave);

            _settings.SaveGroupTree();
            _mockService.Verify(settings => settings.SetValueAsString(_parameterName, expected), Occurred.Once());
        }