Пример #1
0
        public void ShouldParseLessThanThreeChars()
        {
            string      text   = "t te tes test tes te t";
            ParserClass parser = new ParserClass();
            Dictionary <string, int> wordsAmount = parser.ParseTest(text);

            wordsAmount.Should().NotBeNull();
            wordsAmount.Should().NotBeEmpty();
            wordsAmount.Should().HaveCount(2);
            wordsAmount.Should().Contain("tes", 2);
            wordsAmount.Should().Contain("test", 1);
        }
Пример #2
0
        public void ValidateVINNumber_TestNegative_IncorrectSign()
        {
            Car car = new Car();

            car.VIN = "1G4PP5SK0E42000O5" +
                      "";

            Dictionary <bool, string> dictionary = car.ValidateVINNumber();

            dictionary.Should().ContainKey(false);
            dictionary.Should().ContainValue("Wprowadzony numer VIN samochodu jest nieprawiłowy! (Numer VIN nie może zawierać liter I, O i Q!\n");
        }
Пример #3
0
        public void Test_ForEach_In_An_IDictionary()
        {
            IDictionary <string, int> expected = SampleDictionary();
            Dictionary <string, int>  result   = new Dictionary <string, int>();

            expected.ForEach((k, v) =>
            {
                result.Should().NotContainKey(k, "Duplicate key/value pair iteration");
                result[k] = v;
            });

            result.Should().Equal(expected);
        }
Пример #4
0
        public void AddIfMissing_NewKey_ShouldAdd()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>
            {
                { "fubar", 5 }
            };

            dict.AddIfMissing("test", t => t.Length);

            dict.Should().HaveCount(2);
            dict.Should().ContainKey("test");
            dict["test"].Should().Be(4);
        }
Пример #5
0
        public void AddIfMissing_Empty_ShouldAdd()
        {
            // arrange
            var dict = new Dictionary <string, int>();

            // act
            dict.AddIfMissing("test", t => t.Length);

            // assert
            dict.Should().HaveCount(1);
            dict.Should().ContainKey("test");
            dict["test"].Should().Be(4);
        }
Пример #6
0
        public async Task HandleQueryModelChangedNotification_IsPrivate_DoesntPublishesSignal()
        {
            var integrationEvent = Fixtures.Pipelines.FakeCreatedIntegrationEvent();
            var signal           = Fixtures.Pipelines.FakeQueryModelCreatedSignal <int>(integrationEvent);
            var notification     = new QueryModelChangedNotification(signal)
            {
                IsPrivate = true
            };

            await handler.Handle(notification, CancellationToken.None);

            reportBusStore.Should().BeEmpty();
        }
Пример #7
0
        public void AddIfMissing_ExistingKey_ShouldIgnore()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>
            {
                { "fubar", 5 }
            };

            dict.AddIfMissing("fubar", t => 16);

            dict.Should().HaveCount(1);
            dict.Should().ContainKey("fubar");
            dict["fubar"].Should().Be(5);
        }
Пример #8
0
        /// <summary>
        /// Verify that <paramref name="motified"/> contains all of the same items as
        /// <paramref name="original"/>, plus one additional item.
        /// </summary>
        private static void VerifyOriginalTypeHandlers(
            Dictionary <Type, SqlMapper.ITypeHandler> original,
            Dictionary <Type, SqlMapper.ITypeHandler> motified)
        {
            motified.Should().NotBeSameAs(original);
            motified.Should().HaveCount(original.Count + 1);

            foreach (var item in original)
            {
                motified.Should().ContainKey(item.Key)
                .WhoseValue.Should().BeSameAs(item.Value);
            }
        }
Пример #9
0
        public void ItCanSetFailureActions()
        {
            // Given
            GivenServiceCreationIsPossible(ServiceStartType.AutoStart);

            // When
            WhenATestServiceIsCreated(CreateTestServiceDefinition(), startImmediately: false);

            // Then
            failureActions.Should().ContainKey(TestServiceName).WhichValue.Should().Be(TestServiceFailureActions);

            failureActionsFlags.Should().ContainKey(TestServiceName).WhichValue.Should().Be(true);
        }
Пример #10
0
        public void ShouldIgnoreCase()
        {
            string text = "cat cAt CAT";

            ParserClass parser = new ParserClass();
            Dictionary <string, int> wordsAmount = parser.ParseTest(text);

            wordsAmount.Should().NotBeNull();
            wordsAmount.Should().NotBeEmpty();
            wordsAmount.Should().HaveCount(1);
            wordsAmount.Should().Contain("cat", 3);
            wordsAmount.Should().Contain("CAT", 3);
        }
Пример #11
0
        public void GetMetaData_Works()
        {
            MetaDataTool metaDataTool = new MetaDataTool();

            Dictionary <string, string> metaData = metaDataTool.GetMetaData(new MyMetaDataFake {
                A = "someA", B = "someB"
            });

            metaData.Keys.Count.Should().Be(2);
            metaData.Should().ContainKey("capitalA");
            metaData["capitalA"].Should().Be("someA");
            metaData.Should().ContainKey("capitalB");
            metaData["capitalB"].Should().Be("someB");
        }
Пример #12
0
        public void GetOrAdd_NewKey_ShouldInsertAndReturn()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>
            {
                { "fubar", 5 }
            };

            int result = dict.GetOrAdd("test", t => t.Length);

            result.Should().Be(4);
            dict.Should().HaveCount(2);
            dict.Should().ContainKey("test");
            dict["test"].Should().Be(4);
        }
Пример #13
0
        public void GetOrAdd_ExistingKey_ShouldNotInsertAndReturnExisting()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>
            {
                { "fubar", 5 }
            };

            int result = dict.GetOrAdd("fubar", t => 16);

            result.Should().Be(5);
            dict.Should().HaveCount(1);
            dict.Should().ContainKey("fubar");
            dict["fubar"].Should().Be(5);
        }
Пример #14
0
        public void TryAdd_ValueProviderAndEmptyDictionary_ShouldAdd()
        {
            // arrange
            var dict = new Dictionary <string, int>();

            // act
            var result = dict.TryAdd("test", () => 4);

            // assert
            result.Should().BeTrue();
            dict.Should().HaveCount(1);
            dict.Should().ContainKey("test");
            dict["test"].Should().Be(4);
        }
Пример #15
0
        public void SimpleExcludeRareWordsTest()
        {
            var wordsStatistics = new Dictionary <string, int>
            {
                ["word"]      = 5,
                ["something"] = 3,
                ["rare"]      = 1
            };
            var selector = new ExcludeRareWordsSelector(2);

            wordsStatistics = selector.SelectWords(wordsStatistics);
            wordsStatistics.Should().ContainKeys("word", "something");
            wordsStatistics.Should().NotContainKey("rare");
        }
        public void TestMethod14()
        {
            var dictionary = new Dictionary <int, string>
            {
                { 1, "One" },
                { 2, "Two" }
            };

            KeyValuePair <int, string> item1 = new KeyValuePair <int, string>(1, "One");
            KeyValuePair <int, string> item2 = new KeyValuePair <int, string>(2, "Two");

            dictionary.Should().Contain(item1);
            dictionary.Should().Contain(item1, item2);
        }
Пример #17
0
    public void Return_existing_item_if_exists_not_create()
    {
        var sample = new MySampleValue();
        var dict   = new Dictionary <int, MySampleValue> {
            { 100, sample }
        };

        var theValue = dict.GetOrCreate(100);

        dict.Should().HaveCount(1);
        dict.Should().Contain(100, sample);
        dict.Should().ContainValue(theValue);
        theValue.Should().Be(sample);
    }
Пример #18
0
        public static void MustHave <T>(this Dictionary <string, object> dict,
                                        string fieldKey, string subKey, T expctdValue)
        {
            dict.Should().NotBeNull();

            dict.Should().ContainKey(fieldKey);
            var sub = dict[fieldKey] as List <Dictionary <string, object> >;

            sub.Should().NotBeNull();
            sub.Should().HaveCount(1);
            sub[0].Should().ContainKey(subKey);
            sub[0][subKey].Should().Be(expctdValue);

            dict.MustHaveLinks();
        }
Пример #19
0
        public void When_an_assertion_fails_on_ContainKey_succeeding_message_should_be_included()
        {
            // Act
            Action act = () =>
            {
                using var _ = new AssertionScope();
                var values = new Dictionary <int, int>();
                values.Should().ContainKey(0);
                values.Should().ContainKey(1);
            };

            // Assert
            act.Should().Throw <XunitException>()
            .WithMessage("Expected*to contain key 0*Expected*to contain key 1*");
        }
        private void AssertGlobalDataQuote(Dictionary <string, CmcGlobalDataQuote> quotes, bool expectQuoteConversion)
        {
            quotes.Should().NotBeNull();
            quotes.Should().HaveCount(expectQuoteConversion ? ExpectedQuotesWithConversion : ExpectedQuotesWithoutConversion);
            quotes.Should().ContainKeys(expectQuoteConversion ? new string[] { ExpectedUsdQuote, ExpectedEurQuote } : new string[] { ExpectedUsdQuote });

            quotes.First().Value.TotalMarketCap.Should().BePositive();
            quotes.First().Value.TotalVolume24h.Should().BePositive();

            if (expectQuoteConversion)
            {
                quotes.Last().Value.TotalMarketCap.Should().BePositive();
                quotes.Last().Value.TotalVolume24h.Should().BePositive();
            }
        }
Пример #21
0
        public void Dictionaries_empty_and_null_assertions()
        {
            Dictionary <int, string> dictionary = null;

            dictionary.Should().BeNull();

            dictionary = new Dictionary <int, string>();

            dictionary.Should().NotBeNull();
            dictionary.Should().BeEmpty();

            dictionary.Add(1, "first element");

            dictionary.Should().NotBeEmpty();
        }
Пример #22
0
        public void FluentAssertionsDictionaries()
        {
            Dictionary <int, string> dictionary = null;

            dictionary.Should().BeNull();

            dictionary = new Dictionary <int, string>();
            dictionary.Should().NotBeNull();
            dictionary.Should().BeEmpty();
            dictionary.Add(1, "first element");
            dictionary.Should().NotBeEmpty();
            var dictionary1 = new Dictionary <int, string>
            {
                { 1, "One" },
                { 2, "Two" }
            };

            var dictionary2 = new Dictionary <int, string>
            {
                { 1, "One" },
                { 2, "Two" }
            };

            var dictionary3 = new Dictionary <int, string>
            {
                { 3, "Three" },
            };

            dictionary1.Should().Equal(dictionary2);
            dictionary1.Should().NotEqual(dictionary3);
            dictionary1.Should().ContainKey(1);
            dictionary1.Should().ContainKeys(1, 2);
            dictionary1.Should().NotContainKey(9);
            dictionary1.Should().NotContainKeys(9, 10);
            dictionary1.Should().ContainValue("One");
            dictionary1.Should().ContainValues("One", "Two");
            dictionary1.Should().NotContainValue("Nine");
            dictionary1.Should().NotContainValues("Nine", "Ten");

            dictionary2.Should().HaveCount(2);
            dictionary2.Should().NotHaveCount(3);

            dictionary1.Should().HaveSameCount(dictionary2);
            dictionary1.Should().NotHaveSameCount(dictionary3);

            dictionary1.Should().HaveSameCount(dictionary2.Keys);
            dictionary1.Should().NotHaveSameCount(dictionary3.Keys);
        }
 protected void Assert(Dictionary <string, BreakerStats> breakers)
 {
     breakers.Should().NotBeEmpty().And.ContainKey("request");
     var requestBreaker = breakers["request"];
     //requestBreaker.LimitSizeInBytes.Should().BeGreaterThan(0);
     //requestBreaker.Overhead.Should().BeGreaterThan(0);
 }
Пример #24
0
        public void EnsureNoSetSubdirDuplicates(string setCodesStr)
        {
            var setCodes = setCodesStr?.Split(',') ?? Empty <string> .Array;

            foreach (FsPath qualityDir in getQualities(small: true, zoom: true))
            {
                foreach ((_, _, FsPath tokenSuffix) in getIsToken(nonToken: true, token: true))
                {
                    FsPath sourceRoot         = TargetDir.Join(qualityDir).Concat(tokenSuffix);
                    var    caseInsensitiveMap = new Dictionary <string, bool>(StringComparer.OrdinalIgnoreCase);
                    var    caseSensitiveMap   = new Dictionary <string, bool>(StringComparer.Ordinal);
                    using (new AssertionScope($"Set subdirectory duplicates in {sourceRoot}"))
                        foreach (var subdir in sourceRoot.EnumerateDirectories())
                        {
                            string subdirRelative = subdir.Basename();
                            caseInsensitiveMap.Should().NotContainKey(subdirRelative);
                            caseInsensitiveMap[subdirRelative] = true;
                            caseSensitiveMap[subdirRelative]   = true;
                        }

                    using (new AssertionScope($"Affected set duplicates in {sourceRoot}"))
                        foreach (string setCode in setCodes)
                        {
                            if (caseInsensitiveMap.ContainsKey(setCode))
                            {
                                caseSensitiveMap.Should().ContainKey(setCode);
                            }
                        }
                }
            }
        }
        public void MessagingStepReferenceIsAffiliatedToProcess()
        {
            Dictionary <string, object> data   = null;
            var processMessagingStepActivityId = string.Empty;
            var eventStream = new Mock <EventStream>();

            eventStream
            .Setup(e => e.BeginActivity(nameof(ProcessMessagingStep), It.IsAny <string>()))
            .Callback <string, string>((n, i) => processMessagingStepActivityId = i);
            eventStream
            .Setup(es => es.UpdateActivity(nameof(ProcessMessagingStep), It.Is <string>(id => id == processMessagingStepActivityId), It.IsAny <object[]>()))
            .Callback <string, string, object[]>((n, id, d) => data = Enumerable.Range(0, d.Length / 2).ToDictionary(i => (string)d[i * 2], i => d[i * 2 + 1]))
            .Verifiable();

            var processActivityId       = ActivityId.NewActivityId();
            var messagingStepActivityId = ActivityId.NewActivityId();

            var sut = new Process(processActivityId, eventStream.Object);

            sut.AddStep(new MessagingStepReference(messagingStepActivityId, eventStream.Object));

            eventStream.Verify();
            eventStream.Verify(s => s.BeginActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());
            eventStream.Verify(s => s.UpdateActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId, It.IsAny <object[]>()), Times.Once());
            eventStream.Verify(s => s.Flush(), Times.Once());
            eventStream.Verify(s => s.EndActivity(nameof(ProcessMessagingStep), processMessagingStepActivityId), Times.Once());

            var expectedData = new Dictionary <string, object> {
                { nameof(ProcessMessagingStep.MessagingStepActivityID), messagingStepActivityId },
                { nameof(ProcessMessagingStep.ProcessActivityID), processActivityId }
            };

            data.Should().BeEquivalentTo(expectedData);
        }
Пример #26
0
 public void It_should_have_injected_the_context()
 {
     _headers.Should()
     .Contain(new KeyValuePair <string, string>("spanid", _scope.Span.Context.SpanId))
     .And
     .Contain(new KeyValuePair <string, string>("traceid", _scope.Span.Context.TraceId));
 }
        public void Complete_problem()
        {
            // given
            var sut     = Sut();
            var problem = new ProblemDetails
            {
                Detail   = "Some detail",
                Instance = "Some instance",
                Status   = 400,
                Title    = "Some title",
                Type     = "Some type"
            };

            // when
            var d = new Dictionary <string, string>();

            sut.CollectionStandardDimensions(d, problem, null);

            // then
            // then
            var expected = new Dictionary <string, string>
            {
                { $"{DefaultOptions.DimensionPrefix}.Detail", "Some detail" },
                { $"{DefaultOptions.DimensionPrefix}.Instance", "Some instance" },
                { $"{DefaultOptions.DimensionPrefix}.Status", "400" },
                { $"{DefaultOptions.DimensionPrefix}.Title", "Some title" },
                { $"{DefaultOptions.DimensionPrefix}.Type", "Some type" }
            };

            d.Should().BeEquivalentTo(expected);
        }
        public void Append_NotUnique()
        {
            // arrange
            var actualDictionary   = new Dictionary <int, IEnumerable <int> >();
            var expectedDictionary = new Dictionary <int, IEnumerable <int> >
            {
                { 0, new List <int> {
                      0, 1
                  } },
                { 1, new List <int> {
                      0
                  } },
                { 2, new List <int> {
                      0, 1, 1
                  } },
            };

            // act
            actualDictionary.Append(0, 0);
            actualDictionary.Append(0, 1);
            actualDictionary.Append(1, 0);
            actualDictionary.Append(2, 0);
            actualDictionary.Append(2, 1);
            actualDictionary.Append(2, 1);

            // assert
            actualDictionary.Should().BeEquivalentTo(expectedDictionary);
        }
Пример #29
0
        protected void Assert(Dictionary <string, ThreadCountStats> threadPools)
        {
            threadPools.Should().NotBeEmpty().And.ContainKey("management");
            var threadPool = threadPools["management"];

            threadPool.Completed.Should().BeGreaterThan(0);
        }
Пример #30
0
        public void ReadProperties_have_functional_setters()
        {
            var init = 20;

            _DictionaryPropertyAccessor.ReadProperties.ForEach(p => p.Set(_Dictionary, init++));

            var expected = new Dictionary <string, int>
            {
                ["One"]   = 21,
                ["Two"]   = 23,
                ["Three"] = 22,
                ["Four"]  = 20
            };

            _Dictionary.Should().Equal(expected);
        }
        public void Test()
        {
            var transf = _ISession.AllAlbums.Select(all => AlbumDescriptor.CopyAlbum(all as Album, false));

            transf.Count().Should().Be(5);
            foreach (TrackDescriptor ial in transf.SelectMany(al => al.TrackDescriptors))
            {
                DataExchanger<TrackDescriptor> det = new DataExchanger<TrackDescriptor>(ial);
                Dictionary<string, object> res = new Dictionary<string, object>();
                det.Describe(DataExportImportType.WindowsPhone, res.ToObserver());
                res.Should().ContainKey("Artist");
                res.Should().ContainKey("Album");
                res.Should().ContainKey("Genre");
                res.Should().ContainKey("Path");
                res.Should().ContainKey("Name");
            }
        }
Пример #32
0
        public void TestGetOrAdd()
        {
            var dict = new Dictionary<string, string>();
            dict.GetOrAdd("x", () => "a");
            dict.GetOrAdd("x", () => { throw new Exception("Should not be reached."); });

            dict.Should().Equal(new Dictionary<string, string> {["x"] = "a"});
        }
Пример #33
0
        public async Task TestGetOrAddAsync()
        {
            var dict = new Dictionary<string, string>();
            await dict.GetOrAddAsync("x", () => Task.FromResult("a"));
            await dict.GetOrAddAsync("x", () => Task.FromResult("b"));

            dict.Should().Equal(new Dictionary<string, string> {["x"] = "a"});
        }
        public void Behave_ShouldConsumeSectionFromProvider()
        {
            var expectedConfiguration = new KeyValuePair<string, string>("AnyKey", "AnyValue");
            var configuration = new Dictionary<string, string>();

            var configurationSection = ExtensionConfigurationSectionHelper.CreateSection(expectedConfiguration);

            this.sectionProvider.Setup(p => p.GetSection(It.IsAny<string>())).Returns(configurationSection);
            this.consumer.Setup(c => c.Configuration).Returns(configuration);

            this.testee.Behave(this.extensions);

            configuration.Should().Contain(expectedConfiguration);
        }
Пример #35
0
        public void ItShouldCreateTheFollower_GivenWasMissing()
        {
            //g
            var messages = new List<Message>();
            var userToFollowed = new Dictionary<string, List<string>>();
            var command = new FollowCommand("Charlie", "Alice");

            //w
            command.ExecuteUsing(messages, userToFollowed);

            //t
            userToFollowed.Should().ContainKey("Charlie");
            userToFollowed["Charlie"].Should().Contain("Alice");
        }
Пример #36
0
        public async Task TestGetOrAddAsyncRace()
        {
            var mock1 = new Mock();
            var dict = new Dictionary<string, Mock> {["x"] = mock1};

            var mock2 = new Mock();
            var delayedSource = new TaskCompletionSource<Mock>();
            var task = dict.GetOrAddAsync("x", () => delayedSource.Task);
            delayedSource.SetResult(mock2);
            await task;

            dict.Should().Equal(new Dictionary<string, Mock> {["x"] = mock1});

            mock1.IsDisposed.Should().BeFalse();
            mock2.IsDisposed.Should().BeFalse();
        }
 public void FindOrAddShouldCreateNewAndAddIt()
 {
     var testSubject = new Dictionary<string, string>();
     testSubject.FindOrAdd("foo", () => "bar").Should().Be("bar");
     testSubject.Should().Contain(new KeyValuePair<string, string>("foo", "bar"));
 }
        private void CheckViewParameters(Func<IView, IView> setupView, Dictionary<string, string> expectedParameters)
        {
            var collectedParameters = new Dictionary<string, string>();
            var requestedPaths = new List<string>();
            var locator = CreateParameterValidatingLocator(collectedParameters, requestedPaths);

            IView view = new CouchbaseView(new Mock<IMemcachedClient>().Object, locator, "doc", "index");

            setupView(view).ToList();

            collectedParameters.Should().Equal(expectedParameters);
        }
Пример #39
0
        public void ToQueryStringParameters_Empty_ReturnsEmpty ()
        {
            // arrange


            // act
            var result = new Dictionary<string, object> ().ToQueryStringParameters ();


            // assert
            result.Should ().BeEmpty ();
        }