Beispiel #1
0
        public void post_should_call_service()
        {
            // given
            Guid expectedId = Guid.NewGuid();

            var data = new UptimeCheckData()
            {
                Id          = Guid.Empty,
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            var model = new UptimeCheckDataModel()
            {
                Id          = data.Id,
                Name        = data.Name,
                Description = data.Description,
                Interval    = data.Interval,
                //Properties = data.Properties
            };

            _checkServiceMock.Setup(x => x.Create(data)).Returns(expectedId);

            // when
            var actualId = _controller.Post(model);

            // then
            Assert.Equal(expectedId, actualId);
            _checkServiceMock.Verify(x => x.Create(data));
        }
Beispiel #2
0
        public void patch_should_call_service()
        {
            // given
            var data = new UptimeCheckData()
            {
                Id          = Guid.NewGuid(),
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            var model = new UptimeCheckDataModel()
            {
                Id          = data.Id,
                Name        = data.Name,
                Description = data.Description,
                Interval    = data.Interval,
                //Properties = data.Properties
            };

            // when
            _controller.Patch(model);

            // then
            _checkServiceMock.Verify(x => x.Update(data));
        }
Beispiel #3
0
        public async void get_should_use_service()
        {
            // given
            Guid id = Guid.NewGuid();

            var data = new UptimeCheckData()
            {
                Id          = id,
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            _checkServiceMock.Setup(x => x.Load(id))
            .Returns(Task.Run(() => data));

            // when
            UptimeCheckData actualData = await _controller.Get(id);

            // then
            Assert.Equal(data, actualData);
        }
Beispiel #4
0
        public async void getall_should_call_service()
        {
            // given
            Guid id = Guid.NewGuid();

            var data = new UptimeCheckData()
            {
                Id          = id,
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };
            var expectedList = new List <UptimeCheckData>()
            {
                data
            };

            _checkServiceMock.Setup(x => x.LoadAll())
            .Returns(Task.Run(() => expectedList.AsEnumerable()));

            // when
            var actualList = await _controller.GetAll();

            // then
            Assert.Equal(expectedList, actualList);
        }
        public async void update_should_save_instance_and_load_should_have_updated_properties()
        {
            // given
            DocumentStore documentStore = MartenHelper.GetDocumentStore();

            var id              = Guid.NewGuid();
            var repository      = new UptimeCheckRepository(documentStore);
            var uptimeCheckData = new UptimeCheckData()
            {
                Id          = id,
                Name        = "My name",
                Description = "My description",
                Interval    = TimeSpan.FromHours(1)
            };

            repository.Insert(uptimeCheckData);

            uptimeCheckData.Name        = "New name";
            uptimeCheckData.Description = "new description";
            uptimeCheckData.Interval    = TimeSpan.FromDays(30);
            uptimeCheckData.Properties.Add("prop1", "value");

            // when
            repository.Update(uptimeCheckData);

            // then
            var loadedItem = await repository.Load(id);

            Assert.NotNull(loadedItem);
            Assert.Equal(id, loadedItem.Id);
            Assert.Equal(uptimeCheckData.Name, loadedItem.Name);
            Assert.Equal(uptimeCheckData.Description, loadedItem.Description);
            Assert.Equal(uptimeCheckData.Interval, loadedItem.Interval);
            Assert.Equal(uptimeCheckData.Properties["prop1"], "value");
        }
        public async void list_should_return_all_instances()
        {
            // given
            DocumentStore documentStore = MartenHelper.GetDocumentStore();

            var repository       = new UptimeCheckRepository(documentStore);
            var uptimeCheckData1 = new UptimeCheckData()
            {
                Id = Guid.NewGuid()
            };
            var uptimeCheckData2 = new UptimeCheckData()
            {
                Id = Guid.NewGuid()
            };
            var uptimeCheckData3 = new UptimeCheckData()
            {
                Id = Guid.NewGuid()
            };

            repository.Insert(uptimeCheckData1);
            repository.Insert(uptimeCheckData2);
            repository.Insert(uptimeCheckData3);

            // when
            var list = await repository.List();

            // then
            Assert.Equal(3, list.Count());
        }
        public async void delete_should_remove_instance()
        {
            // given
            DocumentStore documentStore = MartenHelper.GetDocumentStore();

            var id              = Guid.NewGuid();
            var repository      = new UptimeCheckRepository(documentStore);
            var uptimeCheckData = new UptimeCheckData()
            {
                Id = id,
            };

            repository.Insert(uptimeCheckData);

            var list = await repository.List();

            int itemCount = list.Count();

            Assert.NotEqual(0, itemCount);

            // when
            await repository.Delete(uptimeCheckData.Id);

            // then
            list = await repository.List();

            itemCount = list.Count();
            Assert.Equal(0, itemCount);
        }
        public async void insert_should_persist_instance_and_load_should_have_filled_properties()
        {
            // given
            DocumentStore documentStore = MartenHelper.GetDocumentStore();

            var id              = Guid.NewGuid();
            var repository      = new UptimeCheckRepository(documentStore);
            var uptimeCheckData = new UptimeCheckData()
            {
                Id          = id,
                Name        = "My name",
                Description = "My description",
                Interval    = TimeSpan.FromHours(1)
            };

            // when
            repository.Insert(uptimeCheckData);

            // then
            var loadedItem = await repository.Load(id);

            Assert.NotNull(loadedItem);
            Assert.Equal(id, loadedItem.Id);
            Assert.Equal(uptimeCheckData.Name, loadedItem.Name);
            Assert.Equal(uptimeCheckData.Description, loadedItem.Description);
            Assert.Equal(uptimeCheckData.Interval, loadedItem.Interval);
        }
        public async void loadall_should_use_repository()
        {
            // given
            var data = new UptimeCheckData()
            {
                Id          = Guid.NewGuid(),
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            var list = new List <UptimeCheckData>()
            {
                data
            };

            _repositoryMock.Setup(x => x.List())
            .Returns(Task.Run(() => list.AsEnumerable()));

            // when
            var actualDataList = await _checkService.LoadAll();

            // then
            Assert.Equal(1, actualDataList.Count());
        }
 public void Update(UptimeCheckData uptimeCheckData)
 {
     using (IDocumentSession session = DocumentStore.LightweightSession())
     {
         session.Update(uptimeCheckData);
         session.SaveChanges();
     }
 }
        public Guid Create(UptimeCheckData uptimeCheckData)
        {
            if (uptimeCheckData.Id == Guid.Empty)
            {
                uptimeCheckData.Id = Guid.NewGuid();
            }

            _uptimeCheckRepository.Insert(uptimeCheckData);

            return(uptimeCheckData.Id);
        }
        public void update_should_use_repository()
        {
            // given
            var data = new UptimeCheckData()
            {
                Id          = Guid.NewGuid(),
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            // when
            _checkService.Update(data);

            // then
            _repositoryMock.Verify(x => x.Update(data));
        }
        public void create_should_use_repository()
        {
            // given
            var data = new UptimeCheckData()
            {
                Name        = "Nom",
                Description = "Nomnom",
                Interval    = TimeSpan.FromHours(1),
                Properties  = new Dictionary <string, string>()
                {
                    { "key", "value" }
                }
            };

            // when
            Guid id = _checkService.Create(data);

            // then
            Assert.NotEqual(id, Guid.Empty);
            _repositoryMock.Verify(x => x.Insert(data));
        }
 public void Update(UptimeCheckData uptimeCheckData)
 {
     _uptimeCheckRepository.Update(uptimeCheckData);
 }
Beispiel #15
0
        public async Task <UptimeCheckData> Get(Guid id)
        {
            UptimeCheckData uptimeCheckData = await _uptimeCheckService.Load(id);

            return(uptimeCheckData);
        }