Пример #1
0
        public void TestStartSession_WhenSaved()
        {
            var jsonBytes = Encoding.ASCII.GetBytes(Constants.NegotiateJsonResponse);

            sqlOperationMock.Setup(s => s.Execute(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>())).Returns(1);
            sqlOperationMock.Setup(s => s.ExecuteAsync(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>()));
            sqlOperationMock.Setup(s => s.Select <SessionDto>(It.IsAny <SelectSqlQuery>(), It.IsAny <object[]>())).Returns(new SessionDto {
                SessionId = 1
            });

            owinRequestMock.Setup(s => s.Path).Returns(new PathString("/negotiate"));
            owinRequestMock.Setup(s => s.Uri).Returns(new Uri("http://fake.com"));
            owinRequestMock.SetReturnsDefault("");

            owinRequestMock.Setup(s => s.Body).Returns(new MemoryStream());
            owinResponseMock.Setup(s => s.Body).Returns(new MemoryStream(jsonBytes));

            var signalrRequest = new SignalrRequest(owinContextMock.Object);

            dataTracingService.StartSession(signalrRequest);

            sqlOperationMock.Verify(v => v.ExecuteAsync(It.IsAny <string>(),
                                                        It.IsAny <object[]>()), Times.Exactly(1));

            sqlOperationMock.Verify(v => v.Execute(It.IsAny <ExecuteSqlQuery>(),
                                                   It.IsAny <object[]>()), Times.Exactly(2));
        }
        public void Test_GetRequestTypeNotValid_LastSegmentis()
        {
            owinRequestMock.Setup(s => s.Path).Returns(new PathString("/signalr/unknown"));

            signalrRequest = new SignalrRequest(owinContextMock.Object);

            Assert.IsFalse(RequestType.None != signalrRequest.Type);
        }
        public void Test_GetRequestTypeValid()
        {
            owinRequestMock.Setup(s => s.Path).Returns(new PathString("/signalr/negotiate"));

            signalrRequest = new SignalrRequest(owinContextMock.Object);

            Assert.IsTrue(RequestType.None != signalrRequest.Type);
        }
        public void Test_Constructor()
        {
            signalrRequest = new SignalrRequest(owinContextMock.Object);

            Assert.IsNotNull(signalrRequest);
            Assert.IsNotNull(signalrRequest.OwinContext);
            Assert.IsNull(signalrRequest.OwinRequestId);
        }
Пример #5
0
        public void TestCompleteRequestTrace_WhenSuccess()
        {
            owinRequestMock.Setup(s => s.Uri).Returns(new Uri("http://fake.com"));
            owinRequestMock.SetReturnsDefault("");
            owinResponseMock.Setup(s => s.Body).Returns(new MemoryStream());

            var signalrRequest = new SignalrRequest(owinContextMock.Object);

            sqlOperationMock.Setup(s => s.ExecuteAsync(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>()));
            dataTracingService.CompleteRequestTrace(signalrRequest);
            sqlOperationMock.Verify(v => v.ExecuteAsync(It.IsAny <ExecuteSqlQuery>(),
                                                        It.IsAny <object[]>()), Times.Exactly(1));
        }
Пример #6
0
        public void TestAddRequestTrace_WhenSuccess()
        {
            var jsonBytes = Encoding.ASCII.GetBytes(Constants.NegotiateJsonResponse);

            sqlOperationMock.Setup(s => s.Execute(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>())).Returns(1);
            sqlOperationMock.Setup(s => s.ExecuteAsync(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>()));

            sqlOperationMock.Setup(s => s.Select <SessionDto>(It.IsAny <SelectSqlQuery>(), It.IsAny <object[]>())).Returns(new SessionDto());

            owinRequestMock.Setup(s => s.Path).Returns(new PathString("/negotiate"));
            owinRequestMock.Setup(s => s.Uri).Returns(new Uri("http://fake.com"));
            owinRequestMock.SetReturnsDefault("");

            owinRequestMock.Setup(s => s.Body).Returns(new MemoryStream());

            var signalrRequest = new SignalrRequest(owinContextMock.Object);
            var result         = dataTracingService.AddRequestTrace(signalrRequest);

            Assert.IsTrue(result);
        }
Пример #7
0
        public void TestAddRequestTrace_OnVariousCollationBranches()
        {
            var jsonBytes = Encoding.ASCII.GetBytes(Constants.NegotiateJsonResponse);

            sqlOperationMock.Setup(s => s.Execute(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>())).Returns(1);
            sqlOperationMock.Setup(s => s.ExecuteAsync(It.IsAny <ExecuteSqlQuery>(), It.IsAny <object[]>()));
            sqlOperationMock.Setup(s => s.Select <SessionDto>(It.IsAny <SelectSqlQuery>(), It.IsAny <object[]>())).Returns(new SessionDto {
                SessionId = 1
            });

            owinRequestMock.Setup(s => s.Path).Returns(new PathString("/negotiate"));
            owinRequestMock.Setup(s => s.Uri).Returns(new Uri("http://fake.com"));
            owinRequestMock.SetReturnsDefault("");

            owinRequestMock.Setup(s => s.Body).Returns(new MemoryStream());
            owinResponseMock.Setup(s => s.Body).Returns(new MemoryStream(jsonBytes));

            owinRequestMock.Setup(s => s.LocalPort).Returns(8080);
            owinRequestMock.Setup(s => s.RemotePort).Returns(8000);
            // CASE 1
            owinRequestMock.Setup(s => s.User).Returns(principleMock.Object);

            var signalrRequest = new SignalrRequest(owinContextMock.Object);

            Assert.IsTrue(dataTracingService.AddRequestTrace(signalrRequest));

            // CASE 2
            principleMock.Setup(s => s.Identity).Returns(identityMock.Object);

            signalrRequest = new SignalrRequest(owinContextMock.Object);
            Assert.IsTrue(dataTracingService.AddRequestTrace(signalrRequest));

            // CASE 3
            principleMock.Setup(s => s.Identity.Name).Returns("");

            signalrRequest = new SignalrRequest(owinContextMock.Object);
            Assert.IsTrue(dataTracingService.AddRequestTrace(signalrRequest));
        }