public void UpdateSimulations_WorksProperly_IfItemsAreOnlyAdded()
        {
            //Arrange
            EFSimulationRepository repository  = new EFSimulationRepository();
            List <SimulationDto>   simulations = new List <SimulationDto>();
            SimulationDto          dto1        = new SimulationDto()
            {
                Id = 1, Name = "a"
            };
            SimulationDto dto2 = new SimulationDto()
            {
                Id = 2, Name = "b"
            };
            SimulationDto dto3 = new SimulationDto()
            {
                Id = 3, Name = "c"
            };
            SimulationDto dto4 = new SimulationDto()
            {
                Id = 4, Name = "d"
            };

            simulations.AddRange(new SimulationDto[] { dto1, dto2, dto3, dto4 });

            //Act
            clearSimulationsTables();
            repository.UpdateSimulations(simulations);
            IEnumerable <SimulationDto> actualRecords = repository.GetSimulations();

            //Assert
            bool areEqual = simulations.HasEqualItems(actualRecords);

            Assert.IsTrue(areEqual);
        }
        public void GetAnalysisTimestampsForSimulation_ReturnsProperDto_IfAnalysisTypeGivenByEnum()
        {
            //Arrange
            EFSimulationRepository      repository = new EFSimulationRepository();
            List <AnalysisTimestampDto> timestamps = new List <AnalysisTimestampDto>();
            AnalysisTimestampDto        dto1       = new AnalysisTimestampDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };
            AnalysisTimestampDto dto2 = new AnalysisTimestampDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto3 = new AnalysisTimestampDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto4 = new AnalysisTimestampDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };

            timestamps.AddRange(new AnalysisTimestampDto[] { dto1, dto2, dto3, dto4 });
            clearSimulationsTables();
            repository.UpdateAnalysisTimestamps(timestamps);

            //Act
            AnalysisTimestampDto dto = repository.GetAnalysisTimestamp(1, 1, 2, AnalysisType.Prices);

            //Assert
            var areEqual = dto4.Equals(dto);

            Assert.IsTrue(areEqual);
        }
        public void GetAnalysisTimestampsForSimulation_ReturnsEmptyCollection_IfThereIsNoTimestampsForGivenSimulation()
        {
            //Arrange
            EFSimulationRepository      repository = new EFSimulationRepository();
            List <AnalysisTimestampDto> timestamps = new List <AnalysisTimestampDto>();
            AnalysisTimestampDto        dto1       = new AnalysisTimestampDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };
            AnalysisTimestampDto dto2 = new AnalysisTimestampDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto3 = new AnalysisTimestampDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto4 = new AnalysisTimestampDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };

            timestamps.AddRange(new AnalysisTimestampDto[] { dto1, dto2, dto3, dto4 });
            clearSimulationsTables();
            repository.UpdateAnalysisTimestamps(timestamps);

            //Act
            IEnumerable <AnalysisTimestampDto> dtos = repository.GetAnalysisTimestampsForSimulation(3).ToArray();

            //Assert
            IEnumerable <AnalysisTimestampDto> expectedDtos = new AnalysisTimestampDto[] { };
            bool areEqualArrays = expectedDtos.HasEqualItems(dtos);

            Assert.IsTrue(areEqualArrays);
        }
        public void GetAnalysisTimestampsForSimulation_ReturnsNull_IfThereIsNoSuchTimestamp()
        {
            //Arrange
            EFSimulationRepository      repository = new EFSimulationRepository();
            List <AnalysisTimestampDto> timestamps = new List <AnalysisTimestampDto>();
            AnalysisTimestampDto        dto1       = new AnalysisTimestampDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };
            AnalysisTimestampDto dto2 = new AnalysisTimestampDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto3 = new AnalysisTimestampDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto4 = new AnalysisTimestampDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };

            timestamps.AddRange(new AnalysisTimestampDto[] { dto1, dto2, dto3, dto4 });
            clearSimulationsTables();
            repository.UpdateAnalysisTimestamps(timestamps);

            //Act
            AnalysisTimestampDto dto = repository.GetAnalysisTimestamp(1, 1, 1, 4);

            //Assert
            Assert.IsNull(dto);
        }
        public void GetSimulations_returnProperDtoCollection()
        {
            //Arrange
            EFSimulationRepository repository  = new EFSimulationRepository();
            List <SimulationDto>   simulations = new List <SimulationDto>();
            SimulationDto          dto1        = new SimulationDto()
            {
                Id = 1, Name = "a"
            };
            SimulationDto dto2 = new SimulationDto()
            {
                Id = 2, Name = "b"
            };
            SimulationDto dto3 = new SimulationDto()
            {
                Id = 3, Name = "c"
            };
            SimulationDto dto4 = new SimulationDto()
            {
                Id = 4, Name = "d"
            };

            simulations.AddRange(new SimulationDto[] { dto1, dto2, dto3, dto4 });
            clearSimulationsTables();
            repository.UpdateSimulations(simulations);

            //Act
            IEnumerable <SimulationDto> dtos = repository.GetSimulations().ToArray();

            //Assert
            bool areEqualArrays = simulations.HasEqualItems(dtos);

            Assert.IsTrue(areEqualArrays);
        }
        public void UpdateAnalysisTimestamps_WorksProperly_IfItemsAreOnlyAdded()
        {
            //Arrange
            EFSimulationRepository      repository = new EFSimulationRepository();
            List <AnalysisTimestampDto> timestamps = new List <AnalysisTimestampDto>();
            AnalysisTimestampDto        dto1       = new AnalysisTimestampDto()
            {
                Id = 1, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };
            AnalysisTimestampDto dto2 = new AnalysisTimestampDto()
            {
                Id = 2, AssetId = 1, TimeframeId = 1, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto3 = new AnalysisTimestampDto()
            {
                Id = 3, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 3, LastAnalysedItem = null, LastAnalysedIndex = null
            };
            AnalysisTimestampDto dto4 = new AnalysisTimestampDto()
            {
                Id = 4, AssetId = 1, TimeframeId = 2, SimulationId = 1, AnalysisTypeId = 2, LastAnalysedItem = new DateTime(2017, 2, 4, 14, 15, 0), LastAnalysedIndex = 100
            };

            timestamps.AddRange(new AnalysisTimestampDto[] { dto1, dto2, dto3, dto4 });

            //Act
            clearSimulationsTables();
            repository.UpdateAnalysisTimestamps(timestamps);
            IEnumerable <AnalysisTimestampDto> actualRecords = repository.GetAnalysisTimestamps();

            //Assert
            bool areEqual = timestamps.HasEqualItems(actualRecords);

            Assert.IsTrue(areEqual);
        }
        public void UpdateSimulations_WorksProperly_IfItemsAreAddedAndUpdated()
        {
            //Arrange
            AnalysisDataQueryDefinition queryDef    = new AnalysisDataQueryDefinition(1, 1);
            EFSimulationRepository      repository  = new EFSimulationRepository();
            List <SimulationDto>        simulations = new List <SimulationDto>();
            SimulationDto dto1 = new SimulationDto()
            {
                Id = 1, Name = "a"
            };
            SimulationDto dto2 = new SimulationDto()
            {
                Id = 2, Name = "b"
            };
            SimulationDto dto3 = new SimulationDto()
            {
                Id = 3, Name = "c"
            };
            SimulationDto dto4 = new SimulationDto()
            {
                Id = 4, Name = "d"
            };

            simulations.AddRange(new SimulationDto[] { dto1, dto2, dto3 });
            clearSimulationsTables();
            repository.UpdateSimulations(simulations);

            //Act
            dto1.Name  = "x";
            dto2.Name += "b";

            IEnumerable <SimulationDto> expectedRecords = new SimulationDto[] { dto1, dto2, dto3, dto4 };

            repository.UpdateSimulations(expectedRecords);
            IEnumerable <SimulationDto> actualRecords = repository.GetSimulations();

            //Assert
            bool areEqual = expectedRecords.HasEqualItems(actualRecords);

            Assert.IsTrue(areEqual);
        }
        public void GetSimulationById_ReturnsProperSimulationDto_IfExists()
        {
            //Arrange
            EFSimulationRepository repository  = new EFSimulationRepository();
            List <SimulationDto>   simulations = new List <SimulationDto>();
            SimulationDto          expected    = new SimulationDto()
            {
                Id = 1, Name = "a"
            };

            simulations.AddRange(new SimulationDto[] { expected });
            clearSimulationsTables();
            repository.UpdateSimulations(simulations);

            //Act
            SimulationDto dto = repository.GetSimulationById(expected.Id);

            //Assert
            var areEqual = expected.Equals(dto);

            Assert.IsTrue(areEqual);
        }
        public void GetSimulationById_ReturnsNull_IfThereIsNoSimulationWithSuchId()
        {
            //Arrange
            EFSimulationRepository repository  = new EFSimulationRepository();
            List <SimulationDto>   simulations = new List <SimulationDto>();
            SimulationDto          dto0        = new SimulationDto()
            {
                Id = 1, Name = "a"
            };
            SimulationDto dto1 = new SimulationDto()
            {
                Id = 1, Name = "b"
            };

            simulations.AddRange(new SimulationDto[] { dto0, dto1 });
            clearSimulationsTables();
            repository.UpdateSimulations(simulations);

            //Act
            SimulationDto dto = repository.GetSimulationById(dto1.Id + 1);

            //Assert
            Assert.IsNull(dto);
        }