Ejemplo n.º 1
0
        public async Task Timeout()
        {
            string json = "{\"Test:\"Success\"}";

            var stopwatch = new Stopwatch();

            await CTest <FakeServerContext>
            .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                       .WithResponse(json)
                                       .WithMethod(HttpMethod.Get)
                                       .WithBeforeReturn(() => Thread.Sleep(1000))
                                       ))
            .WhenAsync(async i =>
            {
                var client     = i.Context.FakeServer.GetClient();
                client.Timeout = TimeSpan.FromMilliseconds(100);
                try
                {
                    await i.MakeTheRequest(client, "http://fake.local/123", HttpMethod.Get);
                }
                catch (Exception e)
                {
                    i.Context.Exception = e;
                }
            })
            .Then(t => Assert.True(t.Context.Exception is TaskCanceledException))
            .ExecuteAsync();
        }
Ejemplo n.º 2
0
 public async Task Test1()
 {
     await CTest <TestContext>
     .Given(g => g.Context.FirstValue = 1)
     .And(g => g.AnotherValue(10))
     .WhenAsync(async w => await w.IAddTheValues())
     .AndAsync(async w => await w.IDivideBy(2))
     .ThenAsync(async t => await t.TheAnswerIs(5.5d))
     .ExecuteAsync();
 }
Ejemplo n.º 3
0
 public async Task EntityCreatesWithIdAndVersion()
 {
     await CTest <EntityContext <EntityClass> >
     .Given(a => a.EntityService())
     .WhenAsync(i => i.CreateTheEntity())
     .Then(t => t.VersionIs(1))
     .And(t => t.IdIsGenerated())
     .And(t => t.EventIsRaised($"{typeof(EntityClass).Name}_Created"))
     .ExecuteAsync();
 }
Ejemplo n.º 4
0
 public async Task Test1()
 {
     await CTest <TestContext>
     .Given(g => g.AValue())
     .And(g => g.AnotherValue(10))
     .When(w => w.IAddTheValues())
     .And(w => w.IDivideBy(2))
     .Then(t => t.TheAnswerIs(5.5d))
     .And(t => t.True())
     .ExecuteAsync();
 }
Ejemplo n.º 5
0
 public async Task NullBody()
 {
     await CTest <FakeServerContext>
     .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                .WithResponse(null)
                                .WithStatusCode(HttpStatusCode.Accepted)))
     .WhenAsync(i => i.MakeTheRequest("http://fake.local/123"))
     .ThenAsync(t => t.JsonIsReturned(null))
     .And(t => t.StatusCodeIs(HttpStatusCode.Accepted))
     .ExecuteAsync();
 }
Ejemplo n.º 6
0
        public async Task SimpleUri()
        {
            string json = "{\"Test:\"Success\"}";

            await CTest <FakeServerContext>
            .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                       .WithResponse(json)))
            .WhenAsync(i => i.MakeTheRequest("http://fake.local/123"))
            .ThenAsync(t => t.JsonIsReturned(json))
            .ExecuteAsync();
        }
Ejemplo n.º 7
0
        public async Task DisposeIsCalled()
        {
            bool          disposed    = false;
            Action <bool> setDisposed = d => disposed = d;

            await CTest <DisposableContext> .Given(q => q.Context.Disposer = setDisposed)
            .When(q => {})
            .Then(q => {})
            .ExecuteAsync();

            Assert.True(disposed);
        }
Ejemplo n.º 8
0
        public async Task ContentTypeHeader()
        {
            string json = "{\"Test:\"Success\"}";

            await CTest <FakeServerContext>
            .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                       .WithResponse(json)
                                       .WithContentType("application/vnd.custom")))
            .WhenAsync(i => i.MakeTheRequest("http://fake.local/123"))
            .ThenAsync(t => t.JsonIsReturned(json))
            .And(t => t.ContentTypeIs("application/vnd.custom"))
            .ExecuteAsync();
        }
Ejemplo n.º 9
0
 public async Task CallingMethodOnEntityRaisesEvent()
 {
     await CTest <EntityContext <EntityClass> >
     .Given(a => a.EntityService())
     .WhenAsync(i => i.CreateTheEntity())
     .AndAsync(async i =>
               await i.MethodIsCalledAsync(async e =>
                                           await e.ArbitraryMethod()))
     .Then(t => t.EventIsRaised($"{typeof(EntityClass).Name}_Created"))
     .And(t => t.EventIsRaised($"{typeof(EntityClass).Name}_ArbitraryMethod"))
     .And(t => t.VersionIs(2))
     .And(t => t.EventIdsMatch())
     .ExecuteAsync();
 }
Ejemplo n.º 10
0
        public async Task LambdaMatcher()
        {
            string json = "{\"Test:\"Success\"}";
            string body = "{\"MatchMe:\"123\"}";

            await CTest <FakeServerContext>
            .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                       .WithResponse("{}")))
            .And(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                     .WithResponse(json)
                                     .WithMethod(HttpMethod.Post)
                                     .WithContentMatch(content =>
                                                       content?.Equals(body) ?? false)
                                     ))
            .WhenAsync(i => i.MakeTheRequest("http://fake.local/123", HttpMethod.Post, body))
            .ThenAsync(t => t.JsonIsReturned(json))
            .ExecuteAsync();
        }
Ejemplo n.º 11
0
 public async Task CallingMethodWithAnonymousObjectRaisesEvent()
 {
     await CTest <EntityContext <EntityClass> >
     .Given(a => a.EntityService())
     .WhenAsync(i => i.CreateTheEntity())
     .AndAsync(async i =>
               await i.MethodIsCalledAsync(async e =>
                                           await e.AnonymousMethod()))
     .Then(t => t.EventIsRaised($"{typeof(EntityClass).Name}_Created"))
     .And(t => t.EventIsRaised($"{typeof(EntityClass).Name}_AnonymousMethod",
                               q => {
         dynamic data = q;
         Assert.True(data.Data1 == "This is my data");
         Assert.True(data.Data2 == 6);
     }))
     .And(t => t.VersionIs(2))
     .And(t => t.EventIdsMatch())
     .ExecuteAsync();
 }
Ejemplo n.º 12
0
        public async Task PrereturnLambda()
        {
            string json = "{\"Test:\"Success\"}";

            var stopwatch = new Stopwatch();

            await CTest <FakeServerContext>
            .Given(i => i.RegisterAUri(b => b.WithUri("http://fake.local/123")
                                       .WithResponse(json)
                                       .WithMethod(HttpMethod.Get)
                                       .WithBeforeReturn(() => Thread.Sleep(1000))
                                       ))
            .WhenAsync(i =>
            {
                stopwatch.Start();
                var value = i.MakeTheRequest("http://fake.local/123", HttpMethod.Get);
                stopwatch.Stop();
                return(value);
            })
            .ThenAsync(t => t.JsonIsReturned(json))
            .And(c => Assert.True(stopwatch.ElapsedMilliseconds > 1000))
            .ExecuteAsync();
        }