Esempio n. 1
0
        public void ReadData_NoConditions_ReadEntity()
        {
            var sqlConnectionMock        = new Mock <ISqlConnectionWrapper>();
            var selectCommandFactoryMock = new Mock <ICommandFactory>();
            var selectCommandMock        = new Mock <IDbCommand>();
            var readerMock = new Mock <IDataReader>();

            selectCommandMock.Setup(x => x.ExecuteReader()).Returns(readerMock.Object);
            readerMock.SetupSequence(x => x.Read())
            .Returns(true)
            .Returns(false);
            readerMock.SetupSequence(x => x.GetInt32(It.IsAny <int>()))
            .Returns(11)
            .Returns(1);
            selectCommandFactoryMock.Setup(x => x.RetriveSelectEntityCommand(It.IsAny <SqlConnection>()))
            .Returns(selectCommandMock.Object);

            var dataHandler = new SqlDataHandler(selectCommandFactoryMock.Object, sqlConnectionMock.Object);
            var entities    = dataHandler.ReadEntities();

            Assert.Single(entities.ToList());
            Assert.Equal(11, entities.ToList().Single().Value);
            Assert.Equal(EntityType.Type1, entities.ToList().Single().Type);
        }