public void ShouldConvertRetrievedDataToUppercase()
        {
            // given
            var storageBrokerMock  = new Mock <IStorageBroker>();
            var returnedDataFiller =
                new Filler <string>();
            List <string> returnedData =
                returnedDataFiller.Create(10).ToList();

            List <string> expectedResult =
                returnedData.Select(item => item.ToUpper())
                .ToList();

            storageBrokerMock.Setup(broker => broker.GetAllData())
            .Returns(returnedData);

            // when
            var dataProcessorService =
                new DataProcessorService(storageBrokerMock.Object);

            List <string> actualResult = dataProcessorService.ProcessData();

            // then
            storageBrokerMock.Verify(broker =>
                                     broker.GetAllData(),
                                     Times.Once,
                                     "Storage broker should be called at least once for data processing.");

            actualResult.Should().BeEquivalentTo(
                expectedResult,
                because: "Returned lists should be both uppercase.");
        }
예제 #2
0
        public void ShouldReturnUpperCaseData()
        {
            // given
            var           storageBrokerMock = new Mock <IStorageBroker>();
            var           storageDataFiller = new Filler <string>();
            List <string> storageData       = storageDataFiller.Create(10).ToList();

            storageBrokerMock.Setup(broker => broker.GetAllData())
            .Returns(storageData);

            List <string> expectedResult = storageData.Select(data => data.ToUpper()).ToList();

            // when
            var           dataProcessorService = new DataProcessorService(storageBrokerMock.Object);
            List <string> actualResult         = dataProcessorService.ProcessData();

            // then
            // Verify broker was called Only once during test
            storageBrokerMock.Verify(broker =>
                                     broker.GetAllData(),
                                     Times.Once,
                                     "Storage broker should be called at least once for data processing");

            actualResult.Should().BeEquivalentTo(
                expectedResult,
                because: "Returned items in list should be uppercase.");
        }