Helper class to generate fake model data
Exemplo n.º 1
0
        public void Should_Match_Class_Property_with_CustomSelector()
        {
            //Create an instance of our test class
            var testInstance = new ContainerClass();

            var measureConst = 1;
            var nameConst = "AaronConst";

            var fake = new Fake<ContainerClass>();

            //Run some tests before we add the custom selector
            var standardFakeInstance = fake.Generate();

            Assert.AreNotEqual(measureConst, standardFakeInstance.Member.Measure);
            Assert.AreNotEqual(nameConst, standardFakeInstance.Member.Name);

            //Add the custom selector for the Member field
            var selector = fake.SetProperty(x => x.Member, () => new CustomMember() {Measure = measureConst, Name = nameConst});

            //Assert.IsTrue(selector.CanBind(typeof(CustomMember)));

            //Generate a new fake with the custom selector implemented
            var customFakeInstance = fake.Generate();

            Assert.AreEqual(measureConst, customFakeInstance.Member.Measure);
            Assert.AreEqual(nameConst, customFakeInstance.Member.Name);
        }
Exemplo n.º 2
0
        public void Should_Match_All_Properties_of_Same_Type()
        {
            //Create an instance of our test class
            var testInstance = new ContainerClass();

            var nameConst = "AaronConst";

            var fake = new Fake<ContainerClass>();

            //Run some tests before we add the custom selector
            var standardFakeInstance = fake.Generate();

            Assert.AreNotEqual(nameConst, standardFakeInstance.Name);

            //Add the custom selector for the Member field
            var selector = fake.SetType(() => nameConst);

            //Assert.IsTrue(selector.CanBind(typeof(string)));

            //Generate a new fake with the custom selector implemented
            var customFakeInstance = fake.Generate();

            Assert.AreEqual(nameConst, customFakeInstance.Name);
            Assert.AreEqual(nameConst, customFakeInstance.OtherName);
            Assert.AreEqual(nameConst, customFakeInstance.Member.Name);
        }
Exemplo n.º 3
0
        public void StubSetterFailsWhenCalled()
        {
            var fake = new Fake<IPropertyInterface>();
            var obj = fake.Object;

            fake.StubSetter(i => { }, (int i) => { });
        }
Exemplo n.º 4
0
        public void Nesting_scopes()
        {
            // Scopes can be nested however deep you'd like:

            var factory = new Fake<IWidgetFactory>();

            using (Fake.CreateScope())
            {
                factory.AnyCall().Throws(new Exception());

                using (Fake.CreateScope())
                {
                    // Will throw since it's configured in outer scope.
                    factory.FakedObject.Create();

                    factory.AnyCall().DoesNothing();

                    // Now will not throw since it's overridden in the inner scope.
                    factory.FakedObject.Create();
                }

                // Will throw  since it's configured in this scope.
                factory.FakedObject.Create();
            }

            // Returns null since it's not configured.
            factory.FakedObject.Create();
        }
Exemplo n.º 5
0
        public void Should_Fake_Single_Instance_of_String()
        {
            var fake = new Fake<string>();

            var stringInstance = fake.Generate();

            Assert.IsNotNullOrEmpty(stringInstance);
        }
Exemplo n.º 6
0
        public void Should_Fake_Single_Instance_of_DateTime()
        {
            var fake = new Fake<DateTime>();

            var dateInstance = fake.Generate();

            Assert.AreNotEqual(DateTime.MinValue, dateInstance);
            Assert.IsTrue(dateInstance.Year > 1);
        }
Exemplo n.º 7
0
        public void Should_Fake_Single_Instance_Of_Rich_Class()
        {
            var fake = new Fake<Project>();

            var projectInstance = fake.Generate();

            Assert.IsNotNull(projectInstance);
            Assert.IsTrue(projectInstance.Versions.Count > 0);
        }
Exemplo n.º 8
0
        public void RecordedCalls_returns_recorded_calls_in_scope()
        {
            var fake = new Fake<IFoo>();
            var fakeObject = Fake.GetFakeManager(fake.FakedObject);

            fake.FakedObject.Bar();

            Assert.That(fake.RecordedCalls, Is.EquivalentTo(fakeObject.RecordedCallsInScope));
        }
Exemplo n.º 9
0
        public void Moo()
        {
            var fake = Fake.New<IHello>();

            fake.Stub(fake.Hello, (string s) => s + "hi");
            var f = new Fake<IHello>();

            Console.WriteLine(fake.Hello("q"));
        }
Exemplo n.º 10
0
        public void RecordedCalls_returns_recorded_calls_from_manager()
        {
            var fake = new Fake<IFoo>();
            var fakeObject = Fake.GetFakeManager(fake.FakedObject);

            fake.FakedObject.Bar();

            fake.RecordedCalls.Should().BeEquivalentTo(fakeObject.GetRecordedCalls());
        }
Exemplo n.º 11
0
        public void Should_Fake_Single_Instance_of_CustomStruct()
        {
            var fake = new Fake<TestStruct>();

            var customStructInstance = fake.Generate();

            Assert.AreNotEqual(DateTime.MinValue, customStructInstance.Date);
            Assert.IsTrue(default(int) != customStructInstance.SomeNumber);
            Assert.IsNotNullOrEmpty(customStructInstance.Id);
        }
Exemplo n.º 12
0
        public void Create_a_fake_object_that_has_methods_for_configuring_the_faked_instance()
        {
            var fake = new Fake<IWidgetFactory>();

            // Calls can be configured directly:
            fake.CallsTo(x => x.Create()).Returns(new Fake<IWidget>().FakedObject);

            // Getting the faked instance:
            var faked = fake.FakedObject;
        }
Exemplo n.º 13
0
        public void Maa()
        {
            var fake = new Fake<IHello>();
            fake.StubSetter<int>(v => fake.Object.Three = v);
            var c = fake.Stub<string, string>(fake.Object.Hello);
            var d = fake.Stub(fake.Object.VoidMethod);

            fake.Object.Hello("a");
            fake.Object.VoidMethod();
            Console.WriteLine(d.Count);
        }
Exemplo n.º 14
0
        public void BugFix_Should_fake_LoggedHttpRequest()
        {
            //arrange
            var fake = new Fake<LoggedHttpRequest>().SetProperty(x => x.CaptureTime, () => new DateTime().Ticks);

            //act
            var instances = fake.Generate(1);

            //assert
            Assert.AreEqual(1, instances.Count);
        }
Exemplo n.º 15
0
        public void Should_Fake_Single_Instance_of_ClassThatContainsStruct()
        {
            var fake = new Fake<ClassWithStruct>();

            var classWithStructInstance = fake.Generate();

            Assert.AreNotEqual(DateTime.MinValue, classWithStructInstance.Struct.Date);
            Assert.IsTrue(default(int) != classWithStructInstance.Struct.SomeNumber);
            Assert.IsNotNullOrEmpty(classWithStructInstance.Struct.Id);
            Assert.IsNotNullOrEmpty(classWithStructInstance.Name);
        }
Exemplo n.º 16
0
        public void Constructor_sets_fake_object_returned_from_fake_creator_to_FakedObject_property()
        {
            var foo = A.Fake<IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.fakeCreator.CreateFake(A<Action<IFakeOptions<IFoo>>>._)).Returns(foo);

                var fake = new Fake<IFoo>();

                fake.FakedObject.Should().BeSameAs(foo);
            }
        }
Exemplo n.º 17
0
        public void Constructor_sets_fake_object_returned_from_fake_creator_to_FakedObject_property()
        {
            var foo = A.Fake<IFoo>();

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.fakeCreator.CreateFake<IFoo>(A<Action<IFakeOptionsBuilder<IFoo>>>._)).Returns(foo);

                var fake = new Fake<IFoo>();

                Assert.That(fake.FakedObject, Is.SameAs(foo));
            }
        }
Exemplo n.º 18
0
        public void AssertArguments()
        {
            var fakeStar = new Fake<IDeathStar>();

            var shoot = fakeStar.Stub(fakeStar.Object.Shoot, (Planet planet) =>
            {
                // Validate arguments using normal C# code
                planet.ShouldNotBe(null);

                // Make the return value depend on the arguments
                return (planet.Name.Contains("oo")) ? "BOOM!" : "Haha, missed!";
            });
        }
Exemplo n.º 19
0
        public void CanStubSetterWithNullDelegates()
        {
            var fake = new Fake<IPropertyInterface>();
            var setCalls = fake.StubSetter<int>(v => fake.Object.GetSet = v);

            fake.Object.GetSet = 1;
            setCalls.Single().Value.ShouldBe(1);

            var getCalls = fake.StubGetter<int>(() => fake.Object.GetSet);

            var q = fake.Object.GetSet;
            getCalls.Single().ReturnValue.ShouldBe(default(int));
        }
Exemplo n.º 20
0
        public void StubbedSetterIsCalledWhenSet()
        {
            var fake = new Fake<IPropertyInterface>();
            var obj = fake.Object;

            int latestValue = 0;

            var setterCalls = fake.StubSetter(i => obj.GetSet = i, (int i) => latestValue = i);
            obj.GetSet = 6;

            latestValue.ShouldBe(6);
            setterCalls.Count.ShouldBe(1);
            setterCalls.Single().Value.ShouldBe(6);
        }
Exemplo n.º 21
0
        public static void CallsToVoidMethodInvokes(Fake<IFoo> fake, bool wasCalled)
        {
            "Given an unnatural fake"
                .x(() => fake = new Fake<IFoo>());

            "And I configure a void method to invoke an action"
                .x(() => fake.CallsTo(f => f.VoidMethod()).Invokes(() => wasCalled = true));

            "When I call the method on the faked object"
                .x(() => fake.FakedObject.VoidMethod());

            "Then it invokes the action"
                .x(() => wasCalled.Should().BeTrue());
        }
Exemplo n.º 22
0
        public static void AnyCall(Fake<IFoo> fake, bool wasCalled)
        {
            "Given an unnatural fake"
                .x(() => fake = new Fake<IFoo>());

            "And I configure any call to invoke an action"
                .x(() => fake.AnyCall().Invokes(() => wasCalled = true));

            "When I call a method on the faked object"
                .x(() => fake.FakedObject.MethodWithResult());

            "Then it invokes the action"
                .x(() => wasCalled.Should().BeTrue());
        }
Exemplo n.º 23
0
        public static void CallsToVoidMethodCallsBaseMethod(
            Fake<AClass> fake)
        {
            "Given an unnatural fake"
                .x(() => fake = new Fake<AClass>());

            "And I configure a void method to call the base method"
                .x(() => fake.CallsTo(f => f.VoidMethod()).CallsBaseMethod());

            "When I call the method on the faked object"
                .x(() => fake.FakedObject.VoidMethod());

            "Then it calls the base method"
                .x(() => fake.FakedObject.WasVoidMethodCalled.Should().BeTrue());
        }
Exemplo n.º 24
0
        public void Calls_to_returns_fake_configuraion_for_the_faked_object_when_function_call_is_specified()
        {
            Expression<Func<IFoo, int>> callSpecification = x => x.Baz();

            var callConfig = A.Fake<IReturnValueArgumentValidationConfiguration<int>>();
            var config = A.Fake<IStartConfiguration<IFoo>>();
            A.CallTo(() => config.CallsTo(callSpecification)).Returns(callConfig);

            var fake = new Fake<IFoo>();
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration<IFoo>(A<FakeManager>.That.Fakes(fake.FakedObject))).Returns(config);

            var result = fake.CallsTo(callSpecification);

            Assert.That(result, Is.SameAs(callConfig));
        }
Exemplo n.º 25
0
        public void Calls_to_returns_fake_configuration_for_the_faked_object_when_void_call_is_specified()
        {
            Expression<Action<IFoo>> callSpecification = x => x.Bar();

            var callConfig = A.Fake<IVoidArgumentValidationConfiguration>();
            var config = A.Fake<IStartConfiguration<IFoo>>();
            A.CallTo(() => config.CallsTo(callSpecification)).Returns(callConfig);

            var fake = new Fake<IFoo>();
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration<IFoo>(A<FakeManager>.That.Fakes(fake.FakedObject))).Returns(config);

            var result = fake.CallsTo(callSpecification);

            result.Should().BeSameAs(callConfig);
        }
Exemplo n.º 26
0
        public static void CallsToVoidMethodThrows(
            Fake<IFoo> fake,
            Exception exception)
        {
            "Given an unnatural fake"
                .x(() => fake = new Fake<IFoo>());

            "And I configure a void method to throw an exception"
                .x(() => fake.CallsTo(f => f.VoidMethod()).Throws<ArithmeticException>());

            "When I call the method on the faked object"
                .x(() => exception = Record.Exception(() => fake.FakedObject.VoidMethod()));

            "Then it throws the exception"
                .x(() => exception.Should().BeAnExceptionOfType<ArithmeticException>());
        }
Exemplo n.º 27
0
        public static void CallsToVoidMethodDoesNothing(
            Fake<AClass> fake,
            Exception exception)
        {
            "Given a strict unnatural fake"
                .x(() => fake = new Fake<AClass>(options => options.Strict()));

            "And I configure a void method to do nothing"
                .x(() => fake.CallsTo(f => f.VoidMethod()).DoesNothing());

            "When I call the method on the faked object"
                .x(() => exception = Record.Exception(() => fake.FakedObject.VoidMethod()));

            "Then it doesn't throw"
                .x(() => exception.Should().BeNull());
        }
Exemplo n.º 28
0
        public void StubbedGetterIsCalledWhenGotten()
        {
            int v = 0;

            var fake = new Fake<IPropertyInterface>();
            var obj = fake.Object;
            var getter = fake.StubGetter(() => obj.GetSet, () => v++);

            obj.GetSet.ShouldBe(0);
            obj.GetSet.ShouldBe(1);
            obj.GetSet.ShouldBe(2);
            obj.GetSet.ShouldBe(3);
            v.ShouldBe(4);

            getter.Count.ShouldBe(4);
            getter.Last().ReturnValue.ShouldBe(3);
        }
Exemplo n.º 29
0
        public void Constructor_that_takes_options_builder_should_set_fake_returned_from_factory_to_FakedObject_property()
        {
            var argumentsForConstructor = new object[] { A.Fake<IFoo>() };
            var fakeReturnedFromFactory = A.Fake<AbstractTypeWithNoDefaultConstructor>(x => x.WithArgumentsForConstructor(argumentsForConstructor));

            Action<IFakeOptions<AbstractTypeWithNoDefaultConstructor>> optionsBuilder = x => { };

            using (Fake.CreateScope())
            {
                A.CallTo(() => this.fakeCreator.CreateFake(optionsBuilder))
                    .Returns(fakeReturnedFromFactory);

                var fake = new Fake<AbstractTypeWithNoDefaultConstructor>(optionsBuilder);

                fake.FakedObject.Should().BeSameAs(fakeReturnedFromFactory);
            }
        }
Exemplo n.º 30
0
        public void AnyCall_returns_fake_configuration_for_the_faked_object()
        {
            // Arrange
            var fake = new Fake<IFoo>();

            var callConfig = A.Fake<IAnyCallConfigurationWithNoReturnTypeSpecified>();
            var config = A.Fake<IStartConfiguration<IFoo>>();

            A.CallTo(() => config.AnyCall()).Returns(callConfig);
            A.CallTo(() => this.startConfigurationFactory.CreateConfiguration<IFoo>(A<FakeManager>.That.Fakes(fake.FakedObject))).Returns(config);

            // Act
            var result = fake.AnyCall();

            // Assert
            result.Should().BeSameAs(callConfig);
        }
Exemplo n.º 31
0
 public void Delete(Fake entity)
 {
     Db.Delete(entity);
 }
Exemplo n.º 32
0
 private static void AddFakeRule <T>(T fakedObject, FakeCallRule rule) where T : class
 {
     Fake.GetFakeObject(fakedObject).AddRule(rule);
 }
Exemplo n.º 33
0
 public void TestInitialize()
 {
     _fakeBuilder            = new FakeClassBuilder <UserQueryParameterGenerator>();
     _fakeUserQueryValidator = _fakeBuilder.GetFake <IUserQueryValidator>();
 }
Exemplo n.º 34
0
 public void Update(Fake entity)
 {
     Db.Update(entity);
 }
 public void TestInitialize()
 {
     _fakeBuilder = new FakeClassBuilder <SavedSearchJsonController>();
     _fakeSavedSearchQueryGenerator = _fakeBuilder.GetFake <ISavedSearchQueryGenerator>();
     _fakeTwitterAccessor           = _fakeBuilder.GetFake <ITwitterAccessor>();
 }
Exemplo n.º 36
0
 public void TestInitialize()
 {
     _fakeBuilder            = new FakeClassBuilder <TweetController>();
     _fakeTweetQueryExecutor = _fakeBuilder.GetFake <ITweetQueryExecutor>();
     _fakeTweetFactory       = _fakeBuilder.GetFake <ITweetFactory>();
 }
Exemplo n.º 37
0
 public void SetUp()
 {
     Fake.InitializeFixture(this);
 }
Exemplo n.º 38
0
 public void SetUp()
 {
     Fake = null;
 }
Exemplo n.º 39
0
 public void Add_should_add_numbers() =>
 Assert.Equal(2, Fake.Add(1, 1));
Exemplo n.º 40
0
 public static EdgeViewModel Get(Guid fromId, Guid toId)
 {
     return(Create(Fake.GetKey()).Default(fromId, toId).Build());
 }
Exemplo n.º 41
0
 public void Sub_should_subtract_numbers() =>
 Assert.Equal(1, Fake.Sub(2, 1));
Exemplo n.º 42
0
 public void TestInitialize()
 {
     _fakeBuilder           = new FakeClassBuilder <HelpController>();
     _fakeHelpQueryExecutor = _fakeBuilder.GetFake <IHelpQueryExecutor>();
 }
Exemplo n.º 43
0
 public QueriesServiceTests()
 {
     _fakeRepo       = new Fake <IEmployeeReadOnlyRepository>();
     _queriesService = new QueriesService(_fakeRepo.FakedObject);
 }
Exemplo n.º 44
0
 public static FakeManager Fakes(this IArgumentConstraintManager <FakeManager> scope, object fake)
 {
     return(scope.Matches(x => x.Equals(Fake.GetFakeManager(fake)), "Specified FakeObject"));
 }
Exemplo n.º 45
0
        public DropCopyNumberEventMock Default()
        {
            Value.Number = Fake.GetCopyNumber(Key);

            return(this);
        }
Exemplo n.º 46
0
 internal static void Issue099_FakingThrowsWithExtensionMethod(Fake <ITester> sample, object item, int result)
 {
     Tools.Asserter.Throws <NotSupportedException>(
         () => sample.Setup(f => f.ExtendedCall(item), Behavior.Returns(result)));
 }
Exemplo n.º 47
0
 public void Insert(Fake entity)
 {
     Db.Save(entity);
 }
Exemplo n.º 48
0
 public void SetUp()
 {
     Fake.InitializeFixture(this);
     _sut.Request = new HttpRequestMessage();
     _sut.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration());
 }
Exemplo n.º 49
0
        public static IFakeAssertions <TFake> Assert <TFake>(this TFake fakedObject) where TFake : class
        {
            Guard.IsNotNull(fakedObject, "fakedObject");

            return(Fake.Assert(fakedObject));
        }
 public void TestInitialize()
 {
     _fakeBuilder = new FakeClassBuilder <TrendsJsonController>();
     _fakeTrendsQueryGenerator = _fakeBuilder.GetFake <ITrendsQueryGenerator>();
     _fakeTwitterAccessor      = _fakeBuilder.GetFake <ITwitterAccessor>();
 }
Exemplo n.º 51
0
#pragma warning restore 649

        public DelegateProxyGeneratorTests()
        {
            Fake.InitializeFixture(this);
        }
Exemplo n.º 52
0
 private static void AddFakeRule <T>(T fakedObject, FakeCallRule rule) where T : class
 {
     Fake.GetFakeManager(fakedObject).AddRuleFirst(rule);
 }
        public void It_should_capture_meaningful_information()
        {
            var featureInfo  = Fake.Object <TestResults.TestFeatureInfo>();
            var scenarioInfo = Fake.Object <TestResults.TestScenarioInfo>();
            var stepInfo     = Fake.Object <TestResults.TestStepInfo>();
            var stepResult   = Fake.Object <TestResults.TestStepResult>();

            stepResult.Parameters = new IParameterResult[]
            {
                new TestResults.TestParameterResult("table",
                                                    TestResults.CreateTabularParameterDetails(ParameterVerificationStatus.Failure)
                                                    .WithKeyColumns("Key")
                                                    .WithValueColumns("Value1", "Value2")
                                                    .AddRow(TableRowType.Matching,
                                                            ParameterVerificationStatus.Success,
                                                            TestResults.CreateValueResult("1"),
                                                            TestResults.CreateValueResult("abc"),
                                                            TestResults.CreateValueResult("some value"))
                                                    .AddRow(TableRowType.Matching,
                                                            ParameterVerificationStatus.Failure,
                                                            TestResults.CreateValueResult("2"),
                                                            TestResults.CreateValueResult("def"),
                                                            TestResults.CreateValueResult("value", "val", ParameterVerificationStatus.Failure))
                                                    .AddRow(TableRowType.Missing,
                                                            ParameterVerificationStatus.Failure,
                                                            TestResults.CreateValueResult("3"),
                                                            TestResults.CreateValueResult("XXX", "<null>", ParameterVerificationStatus.NotProvided),
                                                            TestResults.CreateValueResult("YYY", "<null>", ParameterVerificationStatus.NotProvided))
                                                    .AddRow(TableRowType.Surplus,
                                                            ParameterVerificationStatus.Failure,
                                                            TestResults.CreateValueResult("4"),
                                                            TestResults.CreateValueResult("<null>", "XXX",
                                                                                          ParameterVerificationStatus.Failure),
                                                            TestResults.CreateValueResult("<null>", "YYY",
                                                                                          ParameterVerificationStatus.Failure))
                                                    )
            };
            var scenarioResult = Fake.Object <TestResults.TestScenarioResult>();

            scenarioResult.Status = ExecutionStatus.Passed;

            var featureResult = Fake.Object <TestResults.TestFeatureResult>();
            var comment       = Fake.String();

            var featureNotifier  = (IFeatureProgressNotifier)_notifier;
            var scenarioNotifier = (IScenarioProgressNotifier)_notifier;

            featureNotifier.NotifyFeatureStart(featureInfo);
            scenarioNotifier.NotifyScenarioStart(scenarioInfo);
            scenarioNotifier.NotifyStepStart(stepInfo);
            scenarioNotifier.NotifyStepComment(stepInfo, comment);
            scenarioNotifier.NotifyStepFinished(stepResult);
            scenarioNotifier.NotifyScenarioFinished(scenarioResult);
            featureNotifier.NotifyFeatureFinished(featureResult);

            var expectedTable = @"    table:
    +-+---+----------+----------+
    |#|Key|Value1    |Value2    |
    +-+---+----------+----------+
    |=|1  |abc       |some value|
    |!|2  |def       |val/value |
    |-|3  |<null>/XXX|<null>/YYY|
    |+|4  |XXX/<null>|YYY/<null>|
    +-+---+----------+----------+"
                                .Replace("\r", "")
                                .Replace("\n", Environment.NewLine);

            var expected = new[]
            {
                $"FEATURE: [{string.Join("][", featureInfo.Labels)}] {featureInfo.Name}{Environment.NewLine}  {featureInfo.Description}",
                $"SCENARIO: [{string.Join("][", scenarioInfo.Labels)}] {scenarioInfo.Name}",
                $"  STEP {stepInfo.GroupPrefix}{stepInfo.Number}/{stepInfo.GroupPrefix}{stepInfo.Total}: {stepInfo.Name}...",
                $"  STEP {stepInfo.GroupPrefix}{stepInfo.Number}/{stepInfo.GroupPrefix}{stepInfo.Total}: /* {comment} */",
                $"  STEP {stepResult.Info.GroupPrefix}{stepResult.Info.Number}/{stepResult.Info.GroupPrefix}{stepResult.Info.Total}: {stepResult.Info.Name} ({stepResult.Status} after {stepResult.ExecutionTime.Duration.FormatPretty()}){Environment.NewLine}{expectedTable}",
                $"  SCENARIO RESULT: {scenarioResult.Status} after {scenarioResult.ExecutionTime.Duration.FormatPretty()}{Environment.NewLine}    {scenarioResult.StatusDetails}",
                $"FEATURE FINISHED: {featureResult.Info.Name}"
            };

            Assert.That(_captured.ToArray(), Is.EqualTo(expected));
        }
        public BookMessageMock WithCategory()
        {
            Value.Category = Fake.GetCategoryName(Key);

            return(this);
        }
Exemplo n.º 55
0
 public void TestCleanup()
 {
     Fake.ClearConfiguration(fakePlatformRequestAsyncAggregate);
 }
 public static void SetupPassThrough <T>(this Fake <ICredentialsAccessor> fakeCredentialsAccessor) where T : class
 {
     fakeCredentialsAccessor
     .CallsTo(x => x.ExecuteOperationWithCredentials(It.IsAny <IOAuthCredentials>(), It.IsAny <Func <T> >()))
     .ReturnsLazily((IOAuthCredentials cred, Func <T> f) => f());
 }
Exemplo n.º 57
0
        public void Generic_Fake_with_no_arguments_should_call_fake_object_factory_with_correct_arguments()
        {
            A.Fake <IFoo>();

            Fake.Assert(this.factory).WasCalled(x => x.CreateFake(typeof(IFoo), null, true));
        }
Exemplo n.º 58
0
 public void TestInitialize()
 {
     _fakeBuilder = new FakeClassBuilder <MessageController>();
     _fakeMessageQueryExecutor = _fakeBuilder.GetFake <IMessageQueryExecutor>();
     _fakeMessageFactory       = _fakeBuilder.GetFake <IMessageFactory>();
 }
Exemplo n.º 59
0
 public void Mul_should_multiply_numbers() =>
 Assert.Equal(5, Fake.Mul(2, 3));
Exemplo n.º 60
0
        public void Setup()
        {
            var fixerIoClientMock = new Fake <IFixerIoClient>();

            _rateService = new RateService(
                new Microsoft.Extensions.Logging.Abstractions.NullLogger <RateService>(),
                fixerIoClientMock.FakedObject);
            var mockedResponse = @"
{
  ""success"":true,
  ""timestamp"":1570003747,
  ""base"":""EUR"",
  ""date"":""2019-10-02"",
  ""rates"":{
    ""AED"":4.008976,
    ""AFN"":85.266296,
    ""ALL"":122.081843,
    ""AMD"":518.707939,
    ""ANG"":1.91216,
    ""AOA"":412.610384,
    ""ARS"":62.914919,
    ""AUD"":1.629899,
    ""AWG"":1.965749,
    ""AZN"":1.861021,
    ""BAM"":1.954781,
    ""BBD"":2.199762,
    ""BDT"":92.056782,
    ""BGN"":1.955817,
    ""BHD"":0.411503,
    ""BIF"":2013.392437,
    ""BMD"":1.091477,
    ""BND"":1.510278,
    ""BOB"":7.533863,
    ""BRL"":4.53776,
    ""BSD"":1.089523,
    ""BTC"":0.000133,
    ""BTN"":77.36878,
    ""BWP"":12.046086,
    ""BYN"":2.270052,
    ""BYR"":21392.942712,
    ""BZD"":2.196026,
    ""CAD"":1.443936,
    ""CDF"":1817.308598,
    ""CHF"":1.089623,
    ""CLF"":0.028868,
    ""CLP"":796.554249,
    ""CNY"":7.802313,
    ""COP"":3791.407931,
    ""CRC"":633.176251,
    ""CUC"":1.091477,
    ""CUP"":28.924132,
    ""CVE"":110.217311,
    ""CZK"":25.739863,
    ""DJF"":193.977226,
    ""DKK"":7.465782,
    ""DOP"":56.937422,
    ""DZD"":131.550238,
    ""EGP"":17.78561,
    ""ERN"":16.372243,
    ""ETB"":31.903758,
    ""EUR"":1,
    ""FJD"":2.399447,
    ""FKP"":0.887239,
    ""GBP"":0.889442,
    ""GEL"":3.25811,
    ""GGP"":0.889452,
    ""GHS"":5.872308,
    ""GIP"":0.887239,
    ""GMD"":55.119162,
    ""GNF"":10069.800112,
    ""GTQ"":8.421779,
    ""GYD"":227.938546,
    ""HKD"":8.557014,
    ""HNL"":26.816463,
    ""HRK"":7.413637,
    ""HTG"":104.757729,
    ""HUF"":334.89457,
    ""IDR"":15493.511316,
    ""ILS"":3.805881,
    ""IMP"":0.889452,
    ""INR"":77.801276,
    ""IQD"":1300.05786,
    ""IRR"":45956.625175,
    ""ISK"":135.507119,
    ""JEP"":0.889452,
    ""JMD"":146.13902,
    ""JOD"":0.774078,
    ""JPY"":117.50806,
    ""KES"":113.36135,
    ""KGS"":76.064788,
    ""KHR"":4476.248567,
    ""KMF"":491.491165,
    ""KPW"":982.41808,
    ""KRW"":1315.404037,
    ""KWD"":0.3323,
    ""KYD"":0.907939,
    ""KZT"":423.405369,
    ""LAK"":9611.598351,
    ""LBP"":1647.363336,
    ""LKR"":198.512311,
    ""LRD"":228.25504,
    ""LSL"":16.721169,
    ""LTL"":3.222847,
    ""LVL"":0.660223,
    ""LYD"":1.543294,
    ""MAD"":10.619577,
    ""MDL"":19.300037,
    ""MGA"":4063.783335,
    ""MKD"":61.500378,
    ""MMK"":1669.140336,
    ""MNT"":2911.338742,
    ""MOP"":8.798666,
    ""MRO"":389.657548,
    ""MUR"":39.91039,
    ""MVR"":16.807886,
    ""MWK"":798.595252,
    ""MXN"":21.667773,
    ""MYR"":4.574491,
    ""MZN"":67.628287,
    ""NAD"":16.732395,
    ""NGN"":395.11449,
    ""NIO"":36.623398,
    ""NOK"":9.983627,
    ""NPR"":123.789845,
    ""NZD"":1.747565,
    ""OMR"":0.420213,
    ""PAB"":1.089523,
    ""PEN"":3.671564,
    ""PGK"":3.708237,
    ""PHP"":56.747507,
    ""PKR"":170.86519,
    ""PLN"":4.380696,
    ""PYG"":6951.123624,
    ""QAR"":3.974119,
    ""RON"":4.748684,
    ""RSD"":117.453423,
    ""RUB"":71.46869,
    ""RWF"":1007.869556,
    ""SAR"":4.094349,
    ""SBD"":9.067877,
    ""SCR"":14.954308,
    ""SDG"":49.149742,
    ""SEK"":10.808912,
    ""SGD"":1.511848,
    ""SHP"":1.441735,
    ""SLL"":10423.602373,
    ""SOS"":633.056833,
    ""SRD"":8.140251,
    ""STD"":23533.09925,
    ""SVC"":9.533012,
    ""SYP"":562.11051,
    ""SZL"":16.687545,
    ""THB"":33.464365,
    ""TJS"":10.557472,
    ""TMT"":3.820168,
    ""TND"":3.128719,
    ""TOP"":2.546688,
    ""TRY"":6.265666,
    ""TTD"":7.38444,
    ""TWD"":33.913814,
    ""TZS"":2503.730392,
    ""UAH"":26.727025,
    ""UGX"":4012.596367,
    ""USD"":1.091477,
    ""UYU"":40.163615,
    ""UZS"":10292.024801,
    ""VEF"":10.901124,
    ""VND"":25278.599654,
    ""VUV"":129.093522,
    ""WST"":2.943554,
    ""XAF"":655.62795,
    ""XAG"":0.063237,
    ""XAU"":0.000737,
    ""XCD"":2.94977,
    ""XDR"":0.800852,
    ""XOF"":655.628188,
    ""XPF"":119.199801,
    ""YER"":273.186025,
    ""ZAR"":16.791343,
    ""ZMK"":9824.583546,
    ""ZMW"":14.201746,
    ""ZWL"":351.455489
  }
}";
            var eurBasedRates  = JsonConvert.DeserializeObject <Dictionary <string, decimal> >(
                JObject.Parse(mockedResponse)["rates"].ToString());

            fixerIoClientMock.CallsTo(_ => _.GetEurBasedRates()).Returns(Task.FromResult(eurBasedRates));
        }