Ejemplo n.º 1
0
        /*
         * [Fact]
         * public async Task Timeout_EnsureEventCalled()
         * {
         *  var ctxt = new DefaultHttpContext();
         *
         *  bool eventCalled = false;
         *
         *  Subject.SessionTimeouted += (s, e) =>
         *  {
         *      eventCalled = true;
         *  };
         *
         *  await CreateNew(ctxt, "Test");
         *  Subject.SessionTimeout = TimeSpan.FromMilliseconds(100);
         *  Subject.TimeoutCheckInterval = TimeSpan.FromMilliseconds(10);
         *
         *  Thread.Sleep(150);
         *
         *  Assert.True(eventCalled, "Timeouted event should be called on instance timeout.");
         * }
         *
         * [Fact]
         * public async Task Timeout_EnsureEventCalledWithValidSession()
         * {
         *  var ctxt = new DefaultHttpContext();
         *
         *  bool validId = false;
         *  string sessionId = null;
         *  Subject.SessionTimeouted += (s, e) =>
         *  {
         *      validId = e.Session == sessionId;
         *  };
         *
         *  var session = await CreateNew(ctxt, "Test");
         *  sessionId = session.SessionId;
         *
         *  Subject.SessionTimeout = TimeSpan.FromMilliseconds(100);
         *  Subject.TimeoutCheckInterval = TimeSpan.FromMilliseconds(10);
         *
         *  Thread.Sleep(150);
         *
         *  Assert.True(validId, "Timeouted event should be called with valid session id.");
         * }
         */

        private async Task <IContractSession> CreateNew(DefaultHttpContext ctxt, string sessionId)
        {
            SesionHandler.Setup(v => v.Initialize(ctxt)).Returns(sessionId);
            SesionHandler.Setup(v => v.GetIdentifier(ctxt)).Returns(sessionId);

            return(await Subject.CreateAsync(ctxt, () => Instance));
        }
Ejemplo n.º 2
0
        public async Task GetExisting_DoesNotExist_ThrowsSessionNotFoundException()
        {
            var ctxt = new DefaultHttpContext();

            SesionHandler.Setup(v => v.GetIdentifier(ctxt)).Returns("anything").Verifiable();

            await Assert.ThrowsAsync <SessionNotFoundException>(() => Subject.GetExistingAsync(ctxt, null));

            SesionHandler.Verify();
        }
Ejemplo n.º 3
0
        public async Task Create_EnsureAdded()
        {
            var ctxt      = new DefaultHttpContext();
            var sessionId = "testSessionId";

            SesionHandler.Setup(v => v.Initialize(ctxt)).Returns(sessionId).Verifiable();
            SesionHandler.Setup(v => v.GetIdentifier(ctxt)).Returns(sessionId).Verifiable();

            await Subject.CreateAsync(ctxt, () => Instance);

            Assert.Equal(1, Subject.Count);
        }
Ejemplo n.º 4
0
        public async Task Create_EnsureContractSesion()
        {
            var ctxt      = new DefaultHttpContext();
            var sessionId = "testSessionId";

            SesionHandler.Setup(v => v.Initialize(ctxt)).Returns(sessionId).Verifiable();
            SesionHandler.Setup(v => v.GetIdentifier(ctxt)).Returns(sessionId).Verifiable();

            var result = await Subject.CreateAsync(ctxt, () => Instance);

            Assert.NotNull(result);

            SesionHandler.Verify();
        }