public async Task GetApplicationsStatesAsync_EmptyCheckHistory_ReturnDidNotCheck()
        {
            // arrange
            var uow = new MemoryDbUoW();

            var application = new Application
            {
                Id            = Guid.NewGuid(),
                LastCheckDate = null
            };

            uow.Get <Application>().Add(application);
            uow.SaveChanges();

            var uowFactory = new MemoryDbUowFactory(uow);

            var sut = CreateSut(uowFactory);

            // act
            ApplicationStateViewModel[] viewModels = await sut.GetApplicationsStatesAsync();

            // assert
            Assert.NotEmpty(viewModels);

            var model = viewModels[0];

            Assert.Null(model.CheckDate);
            Assert.Equal(ApplicationState.DidNotCheck, model.State);
        }
        public async Task RemoveApplicationAsync_ExistingGuid_Remove()
        {
            // arrange
            Guid id  = Guid.NewGuid();
            var  uow = new MemoryDbUoW();

            var application = new Application
            {
                Id            = id,
                LastCheckDate = null
            };

            uow.Get <Application>().Add(application);
            uow.SaveChanges();

            var uowFactory = new MemoryDbUowFactory(uow);

            var sut = CreateSut(uowFactory);

            // act
            await sut.RemoveApplicationAsync(id);

            // assert
            var app = uow.Get <Application>().Where(x => x.Id == id).FirstOrDefault();

            Assert.Null(app);
        }
Beispiel #3
0
        public async Task GetDelayAsync_TwoConfigurations_ReturnLastFromDb()
        {
            // arrange
            var configOld = new Configuration
            {
                Id       = 1,
                Interval = TimeSpan.FromSeconds(10)
            };
            var configLatest = new Configuration
            {
                Id       = 2,
                Interval = TimeSpan.FromSeconds(5)
            };
            var uow = new MemoryDbUoW();

            uow.Get <Configuration>().Add(configOld);
            uow.Get <Configuration>().Add(configLatest);
            uow.SaveChanges();

            var uowFactory = new MemoryDbUowFactory(uow);
            var sut        = CreateSut(uowFactory, new AppSettings());

            // act
            TimeSpan delay = await sut.GetDelayAsync();

            // assert
            Assert.NotEqual(0, delay.Seconds);
            Assert.NotEqual(configOld.Interval.Seconds, delay.Seconds);
            Assert.Equal(configLatest.Interval.Seconds, delay.Seconds);
        }
        public async Task GetApplicationsStatesAsync_TwoChecksInHistory_ReturnLatest()
        {
            // arrange
            var uow = new MemoryDbUoW();

            var application = new Application
            {
                Id            = Guid.NewGuid(),
                LastCheckDate = null
            };

            var checkRecordOld = new ApplicationStateHistory
            {
                RecordId      = Guid.NewGuid(),
                Application   = application,
                ApplicationId = application.Id,
                Date          = DateTime.UtcNow.AddMinutes(-10),
                State         = ApplicationState.CheckedWithError
            };

            var checkRecordLatest = new ApplicationStateHistory
            {
                RecordId      = Guid.NewGuid(),
                Application   = application,
                ApplicationId = application.Id,
                Date          = DateTime.UtcNow.AddMinutes(-2),
                State         = ApplicationState.Available
            };

            uow.Get <Application>().Add(application);
            uow.Get <ApplicationStateHistory>().Add(checkRecordOld);
            uow.Get <ApplicationStateHistory>().Add(checkRecordLatest);
            uow.SaveChanges();

            var uowFactory = new MemoryDbUowFactory(uow);

            var sut = CreateSut(uowFactory);

            // act
            ApplicationStateViewModel[] viewModels = await sut.GetApplicationsStatesAsync();

            // assert
            Assert.NotEmpty(viewModels);

            var model = viewModels[0];

            Assert.NotNull(model.CheckDate);
            Assert.Equal(checkRecordLatest.Date, model.CheckDate);
            Assert.Equal(checkRecordLatest.State, model.State);
        }
        public async Task RemoveApplicationAsync_NonExistsGuid_DoNothing()
        {
            // arrange
            Guid id         = Guid.NewGuid();
            var  uow        = new MemoryDbUoW();
            var  uowFactory = new MemoryDbUowFactory(uow);

            var sut = CreateSut(uowFactory);

            // act
            await sut.RemoveApplicationAsync(id);

            // assert
            var app = uow.Get <Application>().Where(x => x.Id == id).FirstOrDefault();

            Assert.Null(app);
        }
        public async Task AddApplicationAsync_SuccessAdded()
        {
            // arrange
            var uow        = new MemoryDbUoW();
            var uowFactory = new MemoryDbUowFactory(uow);

            var name        = "App-08";
            var description = "Test application";
            var url         = "http://localhost:56565";

            var sut = CreateSut(uowFactory);

            // act
            await sut.AddApplicationAsync(name, description, url);

            // assert
            var app = uow.Get <Application>().Where(x => x.Name == name).FirstOrDefault();

            Assert.NotNull(app);
        }
Beispiel #7
0
        public async Task CheckApplicationsAsync_SuccessSaveResult(ApplicationState state)
        {
            // arrange
            var application = new Application
            {
                Id            = Guid.NewGuid(),
                LastCheckDate = null
            };
            var uow = new MemoryDbUoW();

            uow.Get <Application>().Add(application);
            uow.SaveChanges();

            var uowFactory             = new MemoryDbUowFactory(uow);
            var applicationCheckerMock = new Mock <IApplicationChecker>();

            applicationCheckerMock.Setup(x => x.CheckApplicationAsync(It.IsAny <Application>())).ReturnsAsync(
                new CheckResult
            {
                State = state
            });

            var sut = CreateSut(uowFactory, applicationCheckerMock.Object);

            // act
            await sut.CheckApplicationsAsync();

            // assert
            var history = uow.Get <ApplicationStateHistory>().Where(x => x.ApplicationId == application.Id).FirstOrDefault();

            Assert.NotNull(history);
            Assert.Equal(state, history.State);
            Assert.NotEqual(DateTime.MinValue, history.Date);

            var applicationFromDb = uow.Get <Application>().Where(x => x.Id == application.Id).FirstOrDefault();

            Assert.NotNull(applicationFromDb);
            Assert.NotNull(applicationFromDb.LastCheckDate);
            Assert.Equal(history.Date, applicationFromDb.LastCheckDate);
        }