Beispiel #1
0
 public void DeleteAll_WhenTwoCardsAvailable_CardsDeleteCalledTwice()
 {
     var cards = new[] { new Card(), new Card() };
     A.CallTo(() => _trelloFake.Cards.ForBoard(A<IBoardId>.Ignored, BoardCardFilter.All)).Returns(cards);
     _trelloClient.DeleteAll();
     A.CallTo(() => _trelloFake.Cards.Delete(A<ICardId>.Ignored)).MustHaveHappened(Repeated.Exactly.Twice);
 }
 public void OnInitializeAddOrUpdateBugAndAddOrUpdateUserStory()
 {
     var workItems = new[] {
         TfsWorkItem(Bug),
         TfsWorkItem(UserStory)
     };
     A.CallTo(() => _tfsClientFake.GetAllWorkItems()).Returns(workItems);
     _tfsTrelloIntegration.Initialize();
     A.CallTo(() => _trelloClientFake.AddOrUpdateCard(ListName, MyTitle, Description, AssignedTo, Id, BugColor)).MustHaveHappened();
     A.CallTo(() => _trelloClientFake.AddOrUpdateCard(ListName, MyTitle, Description, AssignedTo, Id, UserStoryColor)).MustHaveHappened();
 }
Beispiel #3
0
 public void Init()
 {
     _trelloFake = A.Fake<ITrello>();
     var unityContainer = new UnityContainer();
     Ioc.Configure(unityContainer);
     unityContainer.RegisterInstance(_trelloFake);
     var trelloLists = new []{new List{Name = ListName, Id = "1"}};
     A.CallTo(() => _trelloFake.Lists.ForBoard(TrelloClient.BoardId, ListFilter.All)).Returns(trelloLists);
     var config = A.Fake<ITrelloConfig>();
     A.CallTo(() => config.BoardId).Returns("id");
     _trelloClient = new TrelloClient(config);
 }
Beispiel #4
0
            public void IntepretsDeclareWithSingleName()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "declare"),
                  new Token(TokenType.Identifier, "abc"),
                };

                sut.Run(tokens, context);

                Assert.IsTrue(symbols.Exists("abc"));
            }
        public void SendsNewsletterToKnownCustomers()
        {
            const string Bbv = "bbv";
            const string BbvIct = "bbv ICT";
            const string UnknownCustomer = "not a customer";

            var customers = new[] { Bbv, BbvIct, UnknownCustomer };
            this.testee.SendNewsToCustomers(customers);

            A.CallTo(() => this.mailDispatcher.Send("As a large account customer you receive 5% back when you have a monthly volume of more than 1000$ in April 2013."))
                .MustHaveHappened(Repeated.Exactly.Once);

            A.CallTo(() => this.mailDispatcher.Send("As a new customer you have 10% on your next order over 100$"))
                .MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #6
0
            public void ReturnsValueOfProperty()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.Access, "."),
                  new Token(TokenType.Identifier, "b"),
                };
                symbols.Declare("a");
                symbols.Set("a", new {b = "cde"});

                var result = sut.Run(tokens, context);

                Assert.AreEqual("cde", result);
            }
        public void GetPlaceTrendsAt_WithwoeIdLocation_ReturnsFirstObjectFromTheResults()
        {
            // Arrange
            var queryExecutor = CreateTrendsQueryExecutor();
            var query = TestHelper.GenerateString();
            var woeIdLocation = A.Fake<IWoeIdLocation>();
            var expectedResult = A.Fake<IPlaceTrends>();
            var expectedTwitterAccessorResults = new[] { expectedResult };

            _fakeTrendsQueryGenerator.CallsTo(x => x.GetPlaceTrendsAtQuery(woeIdLocation)).Returns(query);
            _fakeTwitterAccessor.ArrangeExecuteGETQuery(query, expectedTwitterAccessorResults);

            // Act
            var result = queryExecutor.GetPlaceTrendsAt(woeIdLocation);

            // Assert
            Assert.AreEqual(result, expectedResult);
        }
Beispiel #8
0
        private static MethodInfo FindMethodOnTypeThatWillBeInvokedByMethodInfo(Type type, FakeItEasy.Compatibility.MethodInfoWrapper methodWrapper)
        {
            var result =
                (from typeMethod in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                 where HasSameBaseMethod(typeMethod, methodWrapper.Method)
                 select MakeGeneric(typeMethod, methodWrapper.Method)).FirstOrDefault();

            if (result != null)
            {
                return result;
            }

            result = GetMethodOnTypeThatImplementsInterfaceMethod(type, methodWrapper.Method);

            if (result != null)
            {
                return result;
            }

            return GetMethodOnInterfaceTypeImplementedByMethod(type, methodWrapper);
        }
Beispiel #9
0
            public void SetsVariableToAnotherVariable()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "set"),
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.Assignment, "="),
                  new Token(TokenType.Identifier, "b"),
                };
                symbols.Declare("a");
                symbols.Declare("b");
                symbols.Set("b", "def");

                sut.Run(tokens, context);

                Assert.AreEqual("def", symbols.Get("a"));
            }
Beispiel #10
0
            public void SetsVariableToConstantValue()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "set"),
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.Assignment, "="),
                  new Token(TokenType.String, "\"abc\""),
                };
                symbols.Declare("a");

                sut.Run(tokens, context);

                Assert.AreEqual("abc", symbols.Get("a"));
            }
Beispiel #11
0
            public void PrintsSingleVariable()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "print"),
                  new Token(TokenType.Identifier, "abc"),
                };
                symbols.Declare("abc");
                symbols.Set("abc", "def");

                sut.Run(tokens, context);

                A.CallTo(() => core.Print("def")).MustHaveHappened();
            }
Beispiel #12
0
            public void PrintsStringArgument()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "print"),
                  new Token(TokenType.String, "\"abc def\""),
                };

                sut.Run(tokens, context);

                A.CallTo(() => core.Print("abc def")).MustHaveHappened();
            }
Beispiel #13
0
            public void ReturnsValueFromCore()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "load"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.String, "\"abc def\""),
                  new Token(TokenType.ClosedPar, ")"),
                };
                A.CallTo(() => core.OpenPage("abc def")).Returns("def");

                var result = sut.Run(tokens, context);

                Assert.AreEqual("def", result);
            }
Beispiel #14
0
            public void ReturnsListOfItems()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "map"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.Identifier, "list"),
                  new Token(TokenType.Comma, ","),
                  new Token(TokenType.Identifier, "it"),
                  new Token(TokenType.Lambda, "=>"),
                  new Token(TokenType.Identifier, "it"),
                  new Token(TokenType.ClosedPar, ")"),
                };
                symbols.Declare("list");
                symbols.Set("list", new[] {"1", "2", "3"});

                var result = sut.Run(tokens, context);

                CollectionAssert.AreEqual(new[] {"1", "2", "3"}, result);
            }
Beispiel #15
0
            public void LoadsPageFromConstantStringUrl()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "load"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.String, "\"abc def\""),
                  new Token(TokenType.ClosedPar, ")"),
                };

                sut.Run(tokens, context);

                A.CallTo(() => core.OpenPage("abc def")).MustHaveHappened();
            }
        public void DeserializeEnumerable()
        {
            var obj = new[] { new Simple { aaa = "bbb" } };

            var result = DoRoundtripFromObjectTo<IEnumerable<Simple>>(obj);

            result.Should().ContainSingle(item => "bbb".Equals(item.aaa));
        }
Beispiel #17
0
        private static MethodInfo GetMethodOnInterfaceTypeImplementedByMethod(Type type, FakeItEasy.Compatibility.MethodInfoWrapper methodWrapper)
        {
            var reflectedType = methodWrapper.ReflectedType;

            if (reflectedType.GetTypeInfo().IsInterface)
            {
                return null;
            }

            var allInterfaces =
                from i in type.GetInterfaces()
                where TypeImplementsInterface(reflectedType, i)
                select i;

            foreach (var interfaceType in allInterfaces)
            {
                var interfaceMap = reflectedType.GetTypeInfo().GetRuntimeInterfaceMap(interfaceType);

                var foundMethod =
                    (from methodTargetPair in interfaceMap.InterfaceMethods
                         .Zip(interfaceMap.TargetMethods, (interfaceMethod, targetMethod) => new { InterfaceMethod = interfaceMethod, TargetMethod = targetMethod })
                     where HasSameBaseMethod(EnsureNonGeneric(methodWrapper.Method), EnsureNonGeneric(methodTargetPair.TargetMethod))
                     select MakeGeneric(methodTargetPair.InterfaceMethod, methodWrapper.Method)).FirstOrDefault();

                if (foundMethod != null)
                {
                    return GetMethodOnTypeThatImplementsInterfaceMethod(type, foundMethod);
                }
            }

            return null;
        }
Beispiel #18
0
            public void FlattensListOfLists()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "flatten"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.ClosedPar, ")"),
                };
                symbols.Declare("a");
                symbols.Set("a", new[] {new[] {1, 2}, new[] {3, 4}, new[] {5, 6},});

                var result = sut.Run(tokens, context);

                CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5, 6}, result);
            }
 private void SetupGetTfsWorkItemsToUpdate(string workItemTypeName)
 {
     var workItems = new[] {
             TfsWorkItem(workItemTypeName)
     };
     A.CallTo(() => _tfsClientFake.GetTfsWorkItemsToUpdate()).Returns(workItems);
 }
        public void SerializationOfNullInListsAreAlwaysEmittedWhenUsingEmitDefaults()
        {
            var writer = new StringWriter();
            var obj = new[] { "foo", null, "bar" };

            EmitDefaultsSerializer.Serialize(writer, obj);
            var serialized = writer.ToString();
            Dump.WriteLine(serialized);

            Regex.Matches(serialized, "-").Count.Should().Be(3, "there should have been 3 elements");
        }
        public void RoundtripArrayOfIdenticalObjects()
        {
            var z = new Simple { aaa = "bbb" };
            var obj = new[] { z, z, z };

            var result = DoRoundtripOn<Simple[]>(obj);

            result.Should().HaveCount(3).And.OnlyContain(x => z.aaa.Equals(x.aaa));
            result[0].Should().BeSameAs(result[1]).And.BeSameAs(result[2]);
        }
Beispiel #22
0
            public void SetsVariableToResultOfLoadCall()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "set"),
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.Assignment, "="),
                  new Token(TokenType.Identifier, "load"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.String, "\"abc\""),
                  new Token(TokenType.ClosedPar, ")"),
                };
                symbols.Declare("a");
                A.CallTo(() => core.OpenPage("abc")).Returns("def");

                sut.Run(tokens, context);

                Assert.AreEqual("def", symbols.Get("a"));
            }
Beispiel #23
0
            public void LoadsPageFromVariableUrl()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "load"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.Identifier, "abc"),
                  new Token(TokenType.ClosedPar, ")"),
                };
                symbols.Declare("abc");
                symbols.Set("abc", "def");

                sut.Run(tokens, context);

                A.CallTo(() => core.OpenPage("def")).MustHaveHappened();
            }
        public void SerializationIncludesKeyFromAnonymousTypeWhenEmittingDefaults()
        {
            var writer = new StringWriter();
            var obj = new { MyString = (string)null };

            EmitDefaultsSerializer.Serialize(writer, obj, obj.GetType());
            Dump.WriteLine(writer);

            writer.ToString().Should().Contain("MyString");
        }
        public void RoundtripAnonymousType()
        {
            var data = new { Key = 3 };

            var result = DoRoundtripFromObjectTo<Dictionary<string, string>>(data);

            result.Should().Equal(new Dictionary<string, string> {
                { "Key", "3" }
            });
        }
Beispiel #26
0
            public void InterpretsDeclareWithMultipleNames()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "declare"),
                  new Token(TokenType.Identifier, "a"),
                  new Token(TokenType.Identifier, "b"),
                  new Token(TokenType.Identifier, "c"),
                };

                sut.Run(tokens, context);

                Assert.IsTrue(symbols.Exists("a"));
                Assert.IsTrue(symbols.Exists("b"));
                Assert.IsTrue(symbols.Exists("c"));
            }
Beispiel #27
0
            public void LoadsVariable()
            {
                var tokens = new[]
                {
                  new Token(TokenType.Identifier, "find"),
                  new Token(TokenType.OpenPar, "("),
                  new Token(TokenType.Identifier, "page"),
                  new Token(TokenType.Comma, ","),
                  new Token(TokenType.String, "\"//div\""),
                  new Token(TokenType.ClosedPar, ")"),
                };
                symbols.Declare("page");
                symbols.Set("page", "abc");

                sut.Run(tokens, context);

                A.CallTo(() => core.Find("abc", "//div")).MustHaveHappened();
            }