Example #1
0
        public void GetTimeframeById_ReturnsTimeframe_IfExists()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = mockedTimeframeRepositoryForUnitTests();
            ITimeframeService           service          = testServiceInstance(mockedRepository);

            //Act
            Timeframe expectedTimeframe = new Timeframe(DEFAULT_ID, DEFAULT_NAME, DEFAULT_UNIT_TYPE, DEFAULT_UNITS_COUNTER);
            Timeframe timeframe         = service.GetTimeframeById(DEFAULT_ID);

            //Assert
            Assert.AreEqual(expectedTimeframe, timeframe);
        }
Example #2
0
        public void GetTimeframe_ReturnsAlwaysTheSameInstance()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = mockedTimeframeRepositoryForUnitTests();

            //Act
            ITimeframeService service    = testServiceInstance(mockedRepository);
            Timeframe         timeframe1 = service.GetTimeframeById(DEFAULT_ID);
            Timeframe         timeframe2 = service.GetTimeframeByName(DEFAULT_NAME);

            //Assert
            Assert.AreSame(timeframe1, timeframe2);
        }
Example #3
0
        public void GetTimeframeById_ReturnsNull_IfDoesntExist()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = mockedTimeframeRepositoryForUnitTests();
            TimeframeDto dto = null;

            mockedRepository.Setup(c => c.GetTimeframeById(DEFAULT_ID)).Returns(dto);

            //Act
            ITimeframeService service   = testServiceInstance(mockedRepository);
            Timeframe         Timeframe = service.GetTimeframeById(DEFAULT_ID);

            //Assert
            Assert.IsNull(Timeframe);
        }
Example #4
0
        public void GetAllTimeframes_ReturnsProperNumberOfItems()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = new Mock <ITimeframeRepository>();

            TimeframeDto[] dtos = getTimeframeDtos();
            mockedRepository.Setup(r => r.GetAllTimeframes()).Returns(dtos);

            //Act
            ITimeframeService       service    = testServiceInstance(mockedRepository);
            IEnumerable <Timeframe> Timeframes = service.GetAllTimeframes();

            //Assert
            Assert.AreEqual(dtos.Length, ((List <Timeframe>)Timeframes).Count);
        }
Example #5
0
        public void GetTimeframeByName_ReturnsNull_IfDoesntExist()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = new Mock <ITimeframeRepository>();
            TimeframeDto dto = null;

            mockedRepository.Setup(s => s.GetTimeframeBySymbol(DEFAULT_NAME)).Returns(dto);

            //Act
            ITimeframeService service   = testServiceInstance(mockedRepository);
            Timeframe         Timeframe = service.GetTimeframeByName(DEFAULT_NAME);

            //Assert
            Assert.IsNull(Timeframe);
        }
Example #6
0
        public void GetAllTimeframes_AlreadyExistingCurrencyInstancesAreUsed()
        {
            //Arrange
            Mock <ITimeframeRepository> mockedRepository = new Mock <ITimeframeRepository>();

            TimeframeDto[] dtos = getTimeframeDtos();
            TimeframeDto   dto  = dtos[1];

            mockedRepository.Setup(r => r.GetTimeframeById(dto.Id)).Returns(dto);
            mockedRepository.Setup(r => r.GetAllTimeframes()).Returns(dtos);

            //Act
            ITimeframeService       service    = testServiceInstance(mockedRepository);
            Timeframe               timeframe  = service.GetTimeframeById(dto.Id);
            IEnumerable <Timeframe> Timeframes = service.GetAllTimeframes();

            //Assert
            Timeframe fromResultCollection = Timeframes.SingleOrDefault(a => a.GetId() == dto.Id);

            Assert.AreSame(fromResultCollection, timeframe);
        }