Пример #1
0
        public void LogError()
        {
            // Arrange
            var db            = new ErrorCollectModelContainer();
            var mockClient    = GetMockClient();
            var mockException = GetMockException();
            int timeout       = 0;
            Func <Occurance> checkOccurance = () => {
                var occurance = db.Occurances
                                .ToList()
                                .FirstOrDefault(o => {
                    var stack = (o.StackTrace ?? "") == mockException.StackTrace;
                    var type  = o.ExceptionLog != null &&
                                o.ExceptionLog.ExceptionType != null &&
                                o.ExceptionLog.ExceptionType.Name == "NullReferenceExceptionProxy";
                    var help = o.ExceptionLog != null &&
                               o.ExceptionLog.HelpLink != null &&
                               o.ExceptionLog.HelpLink.Link == mockException.HelpLink;
                    var source = o.ExceptionLog != null &&
                                 o.ExceptionLog.Source != null &&
                                 o.ExceptionLog.Source.Application == mockException.Source;
                    return(stack && type && help && source);
                });
                return(occurance);
            };

            using (var host = new ServiceHost(typeof(ErrorCollectService.ErrorCollectService))) {
                host.Open();

                // Act
                mockClient.LogError(mockException);

                // Assert
                Occurance occurance = null;
                while (timeout++ < 1000 && (occurance = checkOccurance.Invoke()) == null)
                {
                    System.Threading.Thread.Sleep(10);
                }

                Assert.IsNotNull(occurance);
                var session = db.Sessions.Find(mockClient.SessionId);
                db.Entry(session).State   = System.Data.Entity.EntityState.Deleted;
                db.Entry(occurance).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
        }
Пример #2
0
        public void StartSession()
        {
            // Arrange
            var db         = new ErrorCollectModelContainer();
            var guid       = "submittedfromunitestlogerror-startsession";
            var username   = "******";
            var platform   = "Test StartSession";
            var mockClient = new RemoteErrorCollect(
                "localhost",
                2358,
                guid,
                platform,
                username
                );
            bool sessionStarted = false;
            int  timeout        = 0;

            using (var host = new ServiceHost(typeof(ErrorCollectService.ErrorCollectService))) {
                host.Open();

                // Act
                mockClient.StartSession(() => { sessionStarted = true; });
                while (!sessionStarted && timeout++ < 10000)
                {
                    System.Threading.Thread.Sleep(10);
                }

                // Assert
                Assert.IsTrue(sessionStarted);
                Assert.IsNotNull(mockClient.SessionId);
                var session = db.Sessions.Find(mockClient.SessionId);
                Assert.IsNotNull(session);
                Assert.AreEqual(guid, session.Device.DeviceGUID);
                Assert.AreEqual(username, session.User.Name);
                Assert.AreEqual(platform, session.Platform.Name);

                db.Entry(session).State = System.Data.Entity.EntityState.Deleted;
                db.SaveChanges();
            }
        }