public void UpdateTrendlines_WorksProperly_IfItemsAreOnlyAdded()
        {
            //Arrange
            EFTrendlineRepository repository = new EFTrendlineRepository();
            List <TrendlineDto>   trendlines = new List <TrendlineDto>();
            TrendlineDto          dto1       = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 5, StartLevel = 1.2345, FootholdIndex = 26, FootholdLevel = 1.3456, Value = 1.234, LastUpdateIndex = 31
            };
            TrendlineDto dto2 = new TrendlineDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 6, StartLevel = 1.4567, FootholdIndex = 23, FootholdLevel = 1.5678, Value = 1.345, LastUpdateIndex = 29
            };
            TrendlineDto dto3 = new TrendlineDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 1, SimulationId = 2, StartIndex = 12, StartLevel = 1.5678, FootholdIndex = 45, FootholdLevel = 1.6789, Value = 1.567, LastUpdateIndex = 47
            };
            TrendlineDto dto4 = new TrendlineDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 1, SimulationId = 2, StartIndex = 8, StartLevel = 1.6789, FootholdIndex = 21, FootholdLevel = 1.7891, Value = 1.678, LastUpdateIndex = 29
            };

            trendlines.AddRange(new TrendlineDto[] { dto1, dto2, dto3, dto4 });

            //Act
            clearTrendlinesTables();
            repository.UpdateTrendlines(trendlines);
            IEnumerable <TrendlineDto> actualRecords = repository.GetTrendlines(1, 1, 1);

            //Assert
            Assert.IsTrue(repository.GetTrendlines(1, 1, 1).HasEqualItems(new TrendlineDto[] { dto1, dto2 }));
            Assert.IsTrue(repository.GetTrendlines(1, 1, 2).HasEqualItems(new TrendlineDto[] { dto3, dto4 }));
        }
        public void GetTrendlines_returnProperDtoCollection()
        {
            //Arrange
            EFTrendlineRepository repository = new EFTrendlineRepository();
            List <TrendlineDto>   trendlines = new List <TrendlineDto>();
            TrendlineDto          dto1       = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 5, StartLevel = 1.2573, FootholdIndex = 27, FootholdLevel = 1.2871, Value = 1.54, LastUpdateIndex = 70
            };
            TrendlineDto dto2 = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 2, SimulationId = 1, StartIndex = 7, StartLevel = 1.0123, FootholdIndex = 52, FootholdLevel = 1.4865, Value = 1.54, LastUpdateIndex = 70
            };
            TrendlineDto dto3 = new TrendlineDto()
            {
                Id = 1, AssetId = 2, TimeframeId = 1, SimulationId = 1, StartIndex = 7, StartLevel = 1.1234, FootholdIndex = 60, FootholdLevel = 1.4564, Value = 1.54, LastUpdateIndex = 70
            };
            TrendlineDto dto4 = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 25, StartLevel = 1.3456, FootholdIndex = 48, FootholdLevel = 1.4564, Value = 1.54, LastUpdateIndex = 70
            };

            trendlines.AddRange(new TrendlineDto[] { dto1, dto2, dto3, dto4 });
            clearTrendlinesTables();
            repository.UpdateTrendlines(trendlines);

            //Act
            IEnumerable <TrendlineDto> dtos = repository.GetTrendlines(1, 1, 1).ToArray();

            //Assert
            IEnumerable <TrendlineDto> expected = new TrendlineDto[] { dto1, dto4 };
            bool areEqualArrays = expected.HasEqualItems(dtos);

            Assert.IsTrue(areEqualArrays);
        }
        public void RemoveTrendlines_IfNotExistingTrendlineIsPassed_NothingHappens()
        {
            //Arrange
            EFTrendlineRepository repository = new EFTrendlineRepository();
            List <TrendlineDto>   trendlines = new List <TrendlineDto>();
            TrendlineDto          dto1       = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 5, StartLevel = 1.2345, FootholdIndex = 26, FootholdLevel = 1.3456, Value = 1.234, LastUpdateIndex = 31
            };
            TrendlineDto dto2 = new TrendlineDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 6, StartLevel = 1.4567, FootholdIndex = 23, FootholdLevel = 1.5678, Value = 1.345, LastUpdateIndex = 29
            };
            TrendlineDto dto3 = new TrendlineDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 12, StartLevel = 1.5678, FootholdIndex = 45, FootholdLevel = 1.6789, Value = 1.567, LastUpdateIndex = 47
            };
            TrendlineDto dto4 = new TrendlineDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 8, StartLevel = 1.6789, FootholdIndex = 21, FootholdLevel = 1.7891, Value = 1.678, LastUpdateIndex = 29
            };

            trendlines.AddRange(new TrendlineDto[] { dto1, dto2, dto3 });
            clearTrendlinesTables();
            repository.UpdateTrendlines(trendlines);
            IEnumerable <TrendlineDto> actualRecords = repository.GetTrendlines(1, 1, 1);

            if (actualRecords.Count() != 3)
            {
                throw new Exception("Test failed while preparing environment");
            }

            //Act
            repository.RemoveTrendlines(new TrendlineDto[] { dto4 });

            //Assert
            IEnumerable <TrendlineDto> recordsAfterRemoving = repository.GetTrendlines(1, 1, 1);
            IEnumerable <TrendlineDto> expectedRecords      = new TrendlineDto[] { dto1, dto2, dto3 };

            Assert.IsTrue(recordsAfterRemoving.HasEqualItems(expectedRecords));
        }
        public void UpdateTrendlines_WorksProperly_IfItemsAreAddedAndUpdated()
        {
            //Arrange
            AnalysisDataQueryDefinition queryDef   = new AnalysisDataQueryDefinition(1, 1);
            EFTrendlineRepository       repository = new EFTrendlineRepository();
            List <TrendlineDto>         trendlines = new List <TrendlineDto>();
            TrendlineDto dto1 = new TrendlineDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 5, StartLevel = 1.2345, FootholdIndex = 26, FootholdLevel = 1.3456, Value = 1.234, LastUpdateIndex = 31
            };
            TrendlineDto dto2 = new TrendlineDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, StartIndex = 6, StartLevel = 1.4567, FootholdIndex = 23, FootholdLevel = 1.5678, Value = 1.345, LastUpdateIndex = 29
            };
            TrendlineDto dto3 = new TrendlineDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 1, SimulationId = 2, StartIndex = 12, StartLevel = 1.5678, FootholdIndex = 45, FootholdLevel = 1.6789, Value = 1.567, LastUpdateIndex = 47
            };
            TrendlineDto dto4 = new TrendlineDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 1, SimulationId = 2, StartIndex = 8, StartLevel = 1.6789, FootholdIndex = 21, FootholdLevel = 1.7891, Value = 1.678, LastUpdateIndex = 29
            };

            trendlines.AddRange(new TrendlineDto[] { dto1, dto2 });
            clearTrendlinesTables();
            repository.UpdateTrendlines(trendlines);

            //Act
            dto1.Value            = 2.345;
            dto2.LastUpdateIndex += 2;
            dto2.Value           += 0.250;
            dto2.LastUpdateIndex  = 32;
            repository.UpdateTrendlines(new TrendlineDto[] { dto1, dto2, dto3, dto4 });

            //Assert
            Assert.IsTrue(repository.GetTrendlines(1, 1, 1).HasEqualItems(new TrendlineDto[] { dto1, dto2 }));
            Assert.IsTrue(repository.GetTrendlines(1, 1, 2).HasEqualItems(new TrendlineDto[] { dto3, dto4 }));
        }