Exemplo n.º 1
0
        public void ShouldSupportGeneratingCollections()
        {
            const int anyCount             = 3;
            var       list                 = Any.List <RecursiveInterface>();
            var       array                = Any.Array <RecursiveInterface>();
            var       set                  = Any.Set <RecursiveInterface>();
            var       dictionary           = Any.Dictionary <RecursiveInterface, ISimple>();
            var       sortedList           = Any.SortedList <string, ISimple>();
            var       sortedDictionary     = Any.SortedDictionary <string, ISimple>();
            var       sortedEnumerable     = Any.EnumerableSortedDescending <string>();
            var       enumerable           = Any.Enumerable <RecursiveInterface>();
            var       concurrentDictionary = Any.ConcurrentDictionary <string, ISimple>();
            var       concurrentBag        = Any.ConcurrentBag <string>();
            var       concurrentQueue      = Any.ConcurrentQueue <string>();
            var       concurrentStack      = Any.ConcurrentStack <string>();

            Assert.Multiple(() =>
            {
                Assert.AreEqual(anyCount, list.Count);
                Assert.AreEqual(anyCount, enumerable.Count());
                Assert.AreEqual(anyCount, array.Length);
                Assert.AreEqual(anyCount, set.Count);
                Assert.AreEqual(anyCount, dictionary.Count);
                Assert.AreEqual(anyCount, sortedList.Count);
                Assert.AreEqual(anyCount, sortedDictionary.Count);
                Assert.AreEqual(anyCount, sortedEnumerable.Count());
                Assert.AreEqual(anyCount, concurrentDictionary.Count);
                Assert.AreEqual(anyCount, concurrentBag.Count);
                Assert.AreEqual(anyCount, concurrentStack.Count);
                Assert.AreEqual(anyCount, concurrentQueue.Count);
            });
        }
Exemplo n.º 2
0
 public void Collections()
 {
     Any.Array <int>();
     Any.List <int>();
     Any.Dictionary <string, int>();
     //...
 }
        public void ShouldAddProjectToPathThenFillCopyForEachReferencedProjects()
        {
            //GIVEN
            var projects   = new ReferencedProjects(Any.Array <ProjectId>(), Any.Instance <INScanSupport>());
            var reference1 = Substitute.For <IReferencedProject>();
            var reference2 = Substitute.For <IReferencedProject>();
            var reference3 = Substitute.For <IReferencedProject>();
            var dependencyPathInProgress = Substitute.For <IDependencyPathInProgress>();
            var clonedPathInProgress1    = Any.Instance <IDependencyPathInProgress>();
            var clonedPathInProgress2    = Any.Instance <IDependencyPathInProgress>();
            var clonedPathInProgress3    = Any.Instance <IDependencyPathInProgress>();
            var project = Any.Instance <IDependencyPathBasedRuleTarget>();


            projects.Add(Any.ProjectId(), reference1);
            projects.Add(Any.ProjectId(), reference2);
            projects.Add(Any.ProjectId(), reference3);

            dependencyPathInProgress.CloneWith(project).Returns(
                clonedPathInProgress1,
                clonedPathInProgress2,
                clonedPathInProgress3);

            //WHEN
            projects.FillAllBranchesOf(dependencyPathInProgress, project);

            //THEN
            reference1.Received(1).FillAllBranchesOf(clonedPathInProgress1);
            reference2.Received(1).FillAllBranchesOf(clonedPathInProgress2);
            reference3.Received(1).FillAllBranchesOf(clonedPathInProgress3);
        }
        public void ShouldYieldEvaluationResultsInCircle()
        {
            //GIVEN
            Displayable d1          = Substitute.For <Displayable>();
            Displayable d2          = Substitute.For <Displayable>();
            Displayable d3          = Substitute.For <Displayable>();
            var         displayable = new CircularDisplayable(d1, d2, d3);
            var         input       = Any.Array <char>();

            var d1Result = Any.String();
            var d2Result = Any.String();
            var d3Result = Any.String();

            d1.Evaluate(input).Returns(d1Result);
            d2.Evaluate(input).Returns(d2Result);
            d3.Evaluate(input).Returns(d3Result);

            //WHEN
            var result1 = displayable.Evaluate(input);
            var result2 = displayable.Evaluate(input);
            var result3 = displayable.Evaluate(input);
            var result4 = displayable.Evaluate(input);

            //THEN
            XAssert.Equal(d1Result, result1);
            XAssert.Equal(d2Result, result2);
            XAssert.Equal(d3Result, result3);
            XAssert.Equal(d1Result, result4);
        }
        public void ShouldPassValueTypeAssertionForProperValueType()
        {
            var integer = Any.Integer();
            var anArray = Any.Array <int>();

            ObjectsOfType <ProperValueType> .ShouldHaveValueSemantics(
                new Func <ProperValueType>[]
            {
                () => new(integer, anArray)
            },
        public void ShouldBeAbleToSayWhetherItsNameMatchesAPattern(string pattern, string className, bool expectedResult)
        {
            //GIVEN
            var declaration = new ClassDeclarationInfo(className, Any.String());

            var @class = new CSharpClass(declaration, Any.Array <ICSharpMethod>());

            //WHEN
            var nameMatches = @class.NameMatches(Pattern.WithoutExclusion(pattern));

            //THEN
            nameMatches.Should().Be(expectedResult);
        }
        public void ShouldFinalizeDependencyPathWithProjectWhenTheReferencesAreEmpty()
        {
            //GIVEN
            var projects = new ReferencedProjects(Any.Array <ProjectId>(), Any.Instance <INScanSupport>());
            var dependencyPathInProgress = Substitute.For <IDependencyPathInProgress>();
            var project = Any.Instance <IDependencyPathBasedRuleTarget>();

            //WHEN
            projects.FillAllBranchesOf(dependencyPathInProgress, project);

            //THEN
            dependencyPathInProgress.Received(1).FinalizeWith(project);
        }
Exemplo n.º 8
0
 public void Any_Array_should_work()
 {
     ForTest.Scenarios
     (
         new[] { "a", "b" },
         new[] { "c", "d" }
     )
     .TestEach(scenario =>
     {
         _mock.ResetCalls();
         _test.WithArray(scenario);
         _mock.VerifyOneCallTo(x => x.WithArray(Any.Array <string>()));
     });
 }
Exemplo n.º 9
0
 public void Any_Array_should_work()
 {
     ForTest.Scenarios
     (
         new[] { "a", "b" },
         new[] { "c", "d" }
     )
     .TestEach(scenario =>
     {
         _mock.Invocations.Clear();
         _test.WithArray(scenario);
         _mock.Verify(x => x.WithArray(Any.Array <string>()), Times.Once);
     });
 }
    public void ShouldAllowSettingBytesBody()
    {
        var httpContextMock = HttpContextMock.Default();
        var content         = Any.Array <byte>(3);

        httpContextMock.Request().WithBytesBody(content);

        var result = new List <byte>
        {
            (byte)httpContextMock.Request().RealInstance.Body.ReadByte(),
            (byte)httpContextMock.Request().RealInstance.Body.ReadByte(),
            (byte)httpContextMock.Request().RealInstance.Body.ReadByte()
        };

        result.Should().Equal(content);
        httpContextMock.Request().RealInstance.Body.Length.Should().Be(3);
    }
        public void ShouldThrowExceptionWhenCollisionsListContainsPairWithTheSameGuest()
        {
            //GIVEN
            var anyGuest         = Any.Integer();
            var guestsCollisions = new List <(int, int)>
            {
                (anyGuest, anyGuest)
            };
            var optimizer = new GuestListTopDownOptimizer(Any.Array <int>(), guestsCollisions);

            //WHEN
            Action act = () => optimizer.GetMaxNonCollidingGuestsConfigurations();

            //THEN
            act.Should().Throw <InvalidCollisionPairException>()
            .WithMessage($"Guest {anyGuest} cannot be colliding with himself");
        }
    }
Exemplo n.º 12
0
        public void ShouldPutTheResultOfEvaluatingDisplayablesOnDisplay()
        {
            //GIVEN
            var display       = Substitute.For <Display>();
            var inputTriggers = Any.Array <char>();
            var result1       = Any.String();
            var result2       = Any.String();
            var result3       = Any.String();

            var rows   = DisplayablesThatReturnFor(inputTriggers, result1, result2, result3);
            var driver = new Driver(display, rows);

            //WHEN
            driver.Display(inputTriggers);

            //THEN
            display.Received(1).Put(result1, result2, result3);
            XReceived.Only(() => display.Put(result1, result2, result3));
        }