public void SetUp()
        {
            var data = new[]
            {
                new Dictionary <string, double>
                {
                    { "one", 0.00052 },
                    { "two", 2.17 },
                    { "three", 3.14 },
                    { "four", 4.42 },
                    { "five", 1.5 },
                    { "six", 16 },
                    { "seven", 71.51 },
                    { "eight", 64.12 },
                    { "nine", 29.00900 },
                    { "ten", 1.00010010001 },
                }
            };

            var dataResult = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            ViewModel.LoadDataCommand.Execute("dummy.path");
        }
 public void ShouldRedirectToProvidedOperations()
 {
     var provider = new FakeProvider();
     var operations = new SolrCloudOperations<FakeEntity>(provider, provider);
     operations.Commit();
     Debug.Assert(provider.LastOperation == "Commit", "Should call the provided Commit method");
 }
예제 #3
0
        public void ShouldRaisePropertyChangedForErrorMessageWhenFailedResultChangedToSuccessful()
        {
            var validPath = @"data.xlsx";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "five", 0 }, { "six", 0 }
                }
            };
            var successfulResult = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(successfulResult);

            var invalidPath  = @"notexisted.file";
            var failedResult = DataResult.CreateFailed("File not found");

            FakeProvider.GetFrom(invalidPath).Returns(failedResult);

            ViewModel.LoadDataCommand.Execute(invalidPath);

            ViewModel.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.ShouldRaisePropertyChangeFor(viewModel => viewModel.ErrorMessage);
        }
예제 #4
0
        public void TestExceptionOnProvider()
        {
            // arrange
            var provider   = new FakeProvider();
            var imageLayer = new ImageLayer("imageLayer")
            {
                DataSource = provider
            };
            var map = new Map();

            map.Layers.Add(imageLayer);
            var       waitHandle = new AutoResetEvent(false);
            Exception exception  = null;

            imageLayer.DataChanged += (sender, args) =>
            {
                exception = args.Error;
                waitHandle.Go();
            };

            // act
            map.RefreshData(new BoundingBox(-1, -1, 0, 0), 1, true);

            // assert
            waitHandle.WaitOne();
            Assert.AreEqual(ExceptionMessage, exception.Message);
        }
예제 #5
0
        public void ShouldResetReportData()
        {
            var inputData = new ScatterInputData
            {
                Data = new[]
                {
                    new Dictionary <string, double> {
                        { "seven", 0.00052 }, { "eight", 1.000012 }, { "nine", 1.1 }
                    },
                    new Dictionary <string, double> {
                        { "seven", 0.0000010101 }, { "eight", 0.12456 }, { "nine", 1.2 }
                    }
                },
                AbscissaColumnName = "seven",
                OrdinateColumnName = "eight"
            };

            var dataResult = DataResult.CreateSuccessful(inputData.Data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            var dummyReportData = GenerateDummyReportData();

            FakeScatterReportCalculator.Calculate(null).ReturnsForAnyArgs(dummyReportData);

            ViewModel.LoadDataCommand.Execute("dummy.path");
            var(abscissaColumn, ordinateColumn) = SelectColumnsForReport("seven", "nine");
            ViewModel.GenerateReportDataCommand.Execute(null);

            ViewModel.LoadDataCommand.Execute("dummy2.path");

            ViewModel.Report.ShouldBeEquivalentTo(ScatterReportData.Empty);
        }
예제 #6
0
            public void GivenAFakeProviderKeyWhichDoesExist_RedirectToAuthenticate_ReturnsAUri()
            {
                // Arrange.
                const string name         = "FakeProviderWoot";
                var          fakeProvider = new FakeProvider(name)
                {
                    AccessToken = new AccessToken
                    {
                        ExpiresOn   = DateTime.Now.AddMinutes(100),
                        PublicToken = "I.Am.A.Public.Token"
                    },
                    UserInformation = new UserInformation
                    {
                        Email    = "*****@*****.**",
                        Gender   = GenderType.Male,
                        Name     = "Fake Name",
                        Id       = "1234567890",
                        UserName = "******"
                    }
                };

                var authenticationService = new AuthenticationService();

                authenticationService.AddProvider(fakeProvider);

                // Act.
                var result = authenticationService.RedirectToAuthenticationProvider(name,
                                                                                    new Uri(
                                                                                        "http://i.want.to.go.home.com/click/feet/together?provider=google"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("http://i.want.to.go.home.com/click/feet/together?provider=google&state=This%20is%20some%20fake%20state", result.AbsoluteUri);
            }
예제 #7
0
        public void ShouldUpdateColumnsWithUniqueValuesWhenGetSuccessfulResult()
        {
            var validPath = @"somefile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "one", 1.23 }, { "two", 45 }
                },
                new Dictionary <string, double> {
                    { "one", 1.0 }, { "two", 128.7 }
                },
                new Dictionary <string, double> {
                    { "one", 3.14 }, { "two", 0.123 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            var expectedColumns = new[]
            {
                new DataColumnViewModel("one")
                {
                    SelectionType = SelectionType.NotSelected
                },
                new DataColumnViewModel("two")
                {
                    SelectionType = SelectionType.NotSelected
                }
            };

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.Columns.ShouldBeEquivalentTo(expectedColumns);
        }
예제 #8
0
        public void TestExceptionOnProvider()
        {
            // arrange
            var provider = new FakeProvider();

            using var imageLayer = new ImageLayer("imageLayer")
                  {
                      DataSource = provider
                  };
            using var map = new Map();
            map.Layers.Add(imageLayer);
            using var waitHandle = new AutoResetEvent(false);
            Exception?exception = null;

            imageLayer.DataChanged += (_, args) => {
                exception = args.Error;
                waitHandle.Go();
            };

            var fetchInfo = new FetchInfo(new MRect(-1, -1, 0, 0), 1, null, ChangeType.Discrete);

            // act
            map.RefreshData(fetchInfo);

            // assert
            waitHandle.WaitOne();
            Assert.AreEqual(ExceptionMessage, exception?.Message);
        }
예제 #9
0
        public void ShouldPassCorrectInputValuesToTheCalculatorWhenSuccessfulyLoadData()
        {
            ScatterInputData actualInputData = null;
            var expectedInputData            = new ScatterInputData
            {
                Data = new[]
                {
                    new Dictionary <string, double> {
                        { "seven", 0.00052 }, { "eight", 1.000012 }, { "nine", 1.1 }
                    },
                    new Dictionary <string, double> {
                        { "seven", 0.0000010101 }, { "eight", 0.12456 }, { "nine", 1.2 }
                    }
                },
                AbscissaColumnName = "seven",
                OrdinateColumnName = "eight"
            };

            var dataResult = DataResult.CreateSuccessful(expectedInputData.Data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            var dummyReportData = new ScatterReportData(Enumerable.Empty <ScatterPoint>(), new ScatterLine(new ScatterPoint(), new ScatterPoint()));

            FakeScatterReportCalculator.Calculate(Arg.Do <ScatterInputData>(input => actualInputData = input)).ReturnsForAnyArgs(dummyReportData);

            ViewModel.LoadDataCommand.Execute("dummy.path");
            SelectColumnsForReport("seven", "eight");

            ViewModel.GenerateReportDataCommand.Execute(null);

            actualInputData.ShouldBeEquivalentTo(expectedInputData);
        }
        public void FindUndeclared_WhenAllGood_PropsAssigned()
        {
            // Arrange
            var provider   = new FakeProvider();
            var transition = new _6FindUndeclaredParameters(provider);
            var state      = new State
            {
                _5QueryAfterScaffolding = @"/* .sql query managed by QueryFirst add-in */


-- designTime - put parameter declarations and design time initialization here


-- endDesignTime
select * from customers,
",
                _4Config = new QFConfigModel
                {
                    defaultConnection = "SomeConnectionString"
                }
            };
            string outMsg;

            // Act
            transition.Go(ref state, out outMsg);
            // Assert
            state._6FinalQueryTextForCode.Should().NotBeNullOrEmpty();
            state._6FinalQueryTextForCode.Should().NotContain("-- designTime", "designTime flags have been converted to hide section");
            state._6NewParamDeclarations.Should().NotBeNullOrEmpty();
            state._6QueryWithParamsAdded.Should().NotBeNullOrEmpty();
        }
예제 #11
0
        public void ShouldClearColumnsWhenGetFailedResult()
        {
            var path         = @"notExistedFile.xls";
            var failedResult = DataResult.CreateFailed("File not found");

            FakeProvider.GetFrom(path).Returns(failedResult);

            ViewModel.LoadDataCommand.Execute(path);

            ViewModel.Columns.Should().BeEmpty();
        }
예제 #12
0
        public void IfExistsMoreProvidersThenReturnRatesFromAll()
        {
            var subprovider1 = new FakeProvider(new ExchangeRate(new Currency("EUR"), new Currency("CZK"), 27));
            var subprovider2 = new FakeProvider(new ExchangeRate(new Currency("USD"), new Currency("CZK"), 22));

            var provider = new ExchangeRateProvider(new[] { subprovider1, subprovider2 });
            var result   = provider.GetExchangeRates(new[] { new Currency("EUR"), new Currency("USD") }).ToArray();

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual(27, result.Single(r => r.SourceCurrency.Code == "EUR").Value);
            Assert.AreEqual(22, result.Single(r => r.SourceCurrency.Code == "USD").Value);
        }
예제 #13
0
        public void ShouldRaiseOnPropertyChangedForErrorMessageWhenGetFailedResult()
        {
            var path         = @"file.txt";
            var failedResult = DataResult.CreateFailed("Provider doesn not support this type of file");

            FakeProvider.GetFrom(path).Returns(failedResult);
            ViewModel.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(path);

            ViewModel.ShouldRaisePropertyChangeFor(viewModel => viewModel.ErrorMessage);
        }
예제 #14
0
        public void IfCurrencyIsNotRequestedThenDontReturnIt()
        {
            var subprovider = new FakeProvider(
                new ExchangeRate(new Currency("EUR"), new Currency("CZK"), 27),
                new ExchangeRate(new Currency("USD"), new Currency("CZK"), 22));

            var provider = new ExchangeRateProvider(new[] { subprovider });
            var result   = provider.GetExchangeRates(new[] { new Currency("EUR") }).ToArray();

            Assert.AreEqual(1, result.Length);
            Assert.AreEqual("EUR", result.Single().SourceCurrency.Code);
        }
예제 #15
0
        private void ConfigureDataForCanExecuteTests()
        {
            var data = new[]
            {
                new Dictionary <string, double> {
                    { "one", 0.00052 }, { "two", 1.000012 }, { "three", 1.1 }
                }
            };

            var dataResult = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(null).ReturnsForAnyArgs(dataResult);

            ViewModel.LoadDataCommand.Execute("dummy.path");
        }
예제 #16
0
        public void ShouldRaisePropertyChangedForAbscissaColumnName()
        {
            var validPath = @"anotherFile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 1.23 }, { "five", 4.785 }, { "two", 42 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            ViewModel.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.ShouldRaisePropertyChangeFor(viewmodel => viewmodel.AbscissaColumnName);
        }
예제 #17
0
        public void ShouldRaiseCanExecuteForGenerateReportDataCommand()
        {
            var validPath = @"anotherFile.xls";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 1.23 }, { "five", 4.785 }, { "two", 42 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);
            ViewModel.GenerateReportDataCommand.MonitorEvents();

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.GenerateReportDataCommand.ShouldRaise("CanExecuteChanged");
        }
예제 #18
0
        public void Should_Register_Found_Providers_In_Container()
        {
            // Given
            var scanner = new Mock <ITailProviderScannerService>();
            IEnumerable <Assembly> assemblies;
            var provider  = new FakeProvider();
            var providers = new List <Type> {
                provider.GetType()
            };

            scanner.Setup(x => x.Scan(out assemblies)).Returns(() => providers);

            // When
            var bootstrapper = new TestBootstrapper(scanner.Object);

            // Then
            Assert.True(bootstrapper.HasBinding <ITailProvider>());
        }
예제 #19
0
        public void ShouldClearErrorMessageWhenGetSuccessfulResult()
        {
            var validPath = @"file.csv";
            var data      = new[]
            {
                new Dictionary <string, double> {
                    { "three", 0.2 }, { "four", -45.34 }
                },
                new Dictionary <string, double> {
                    { "three", 0 }, { "four", 1.55 }
                }
            };
            var result = DataResult.CreateSuccessful(data);

            FakeProvider.GetFrom(validPath).Returns(result);

            ViewModel.LoadDataCommand.Execute(validPath);

            ViewModel.ErrorMessage.Should().BeNull();
        }
예제 #20
0
        private IAuthenticationProvider GetAuthenticationProvider(string providerKey)
        {
            if (string.IsNullOrEmpty(providerKey))
            {
                throw new ArgumentNullException("providerKey");
            }

            TraceSource.TraceVerbose("Trying to retrieve a provider for the given key: " + providerKey);

            IAuthenticationProvider provider = null;

            // Dictionary keys are case sensitive.
            var key = providerKey.ToLowerInvariant();

            if (_authenticationProviderFactory.AuthenticationProviders.ContainsKey(key))
            {
                TraceSource.TraceVerbose("Found registered provider: " + key);
                provider = _authenticationProviderFactory.AuthenticationProviders[key];
            }
            else if (providerKey.StartsWith("fake", StringComparison.InvariantCultureIgnoreCase))
            {
                // Ah-ha! We've been asked for a fake key :P
                TraceSource.TraceVerbose("Request for a *Fake* provider. Creating the fake provider: " + providerKey);
                provider = new FakeProvider(providerKey);
            }

            // So, did we get a real or fake key?
            if (provider == null)
            {
                var errorMessage = string.Format("There was no provider registered for the given key: {0}.", providerKey);
                TraceSource.TraceError(errorMessage);
                throw new InvalidOperationException(errorMessage);
            }

            TraceSource.TraceVerbose("Found - Provider: {0}.",
                                     string.IsNullOrEmpty(provider.Name)
                                         ? "-no provider name-"
                                         : provider.Name);

            return(provider);
        }
 public void ShouldEventuallyUseAllActiveReplicasForRead()
 {
     var provider = new FakeProvider();
     var state = provider.GetCloudState();
     var count = state.Collections.Values
         .SelectMany(collection => collection.Shards.Values)
         .SelectMany(shard => shard.Replicas.Values)
         .Where(replica => replica.IsActive)
         .Select(replica => replica.Url)
         .Distinct()
         .Count();
     var urls = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
     foreach (var collection in state.Collections.Values) {
         var operations = new SolrCloudOperations<FakeEntity>(provider, provider, collection.Name);
         for (var i = 0; i < 10*count; i++) {
             operations.Ping();
             urls.Add(provider.LastUrl);
         }
     }
     Debug.Assert(urls.Count == count, "Should eventually use all active replicas for read");
 }
예제 #22
0
        /// <summary>
        /// Consider this your playground where you can use Method Signatures to configure and manipulate the created
        /// Subscribers and Data
        /// </summary>
        private static void Main(string[] args)
        {
            Pub publisher = new Pub();
            var sub1      = new Sub("Sub1", "I Only care about numerical values", publisher, new IHandler[] { new ValueHandler() });
            var sub2      = new Sub("Sub2", "I Only care about Lists", publisher, new IHandler[] { new CollectionHandler() });
            var sub3      = new Sub("Sub3", "I Only care about Objects", publisher, new IHandler[] { new ObjectHandler() });
            var sub4      = new Sub("Sub4", "I care about everything", publisher, new IHandler[] { new ValueHandler(), new ObjectHandler(), new CollectionHandler() });

            #region Fake Data Manipulations Before publishing to illustrate mutations
            //Lets assume you got something from layer above and now you need to change it before passing it to the Subscribers
            var fakeCollection = FakeProvider.GetInitialListOfStrings();
            FakeWorkingUnit.MyFakeDataMutation(fakeCollection);
            #endregion Fake Data Manipulations Before publishing to illustrate mutations

            publisher.Raise(FakeWorkingUnit.MyFakeDataMutation(FakeProvider.GetInitialValue()));
            publisher.Raise(fakeCollection);
            publisher.Raise(FakeWorkingUnit.MyFakeDataMutation(string.Empty)); // This is used to trigger object handler and subscriber since string is an object that shares traits with primitives :)

            Console.WriteLine("Hit Enter to kill this");

            Console.ReadLine();
        }
            public void GivenAFakeProviderKeyWhichDoesExist_RedirectToAuthenticate_ReturnsAUri()
            {
                // Arrange.
                const string name = "FakeProviderWoot";
                var fakeProvider = new FakeProvider(name)
                {
                    AccessToken = new AccessToken
                    {
                        ExpiresOn = DateTime.Now.AddMinutes(100),
                        PublicToken = "I.Am.A.Public.Token"
                    },
                    UserInformation = new UserInformation
                    {
                        Email = "*****@*****.**",
                        Gender = GenderType.Male,
                        Name = "Fake Name",
                        Id = "1234567890",
                        UserName = "******"
                    }
                };

                var authenticationService = new AuthenticationService();
                authenticationService.AddProvider(fakeProvider);

                // Act.
                var result = authenticationService.RedirectToAuthenticationProvider(name,
                                                                       new Uri(
                                                                           "http://i.want.to.go.home.com/click/feet/together?provider=google"));

                // Assert.
                Assert.NotNull(result);
                Assert.Equal("http://i.want.to.go.home.com/click/feet/together?provider=google&state=This%20is%20some%20fake%20state", result.AbsoluteUri);
            }
        public void GetInitalValueTest()
        {
            int value = FakeProvider.GetInitialValue();

            Assert.IsTrue(value >= 0);
        }
        public void GetInitialListOfStringsTest()
        {
            List <string> listOfStrings = FakeProvider.GetInitialListOfStrings();

            Assert.AreEqual(listOfStrings.Count, 4);
        }