Ejemplo n.º 1
0
        public async Task Update()
        {
            //arrange
            var sprocs = Substitute.For<ISqlClient>();
            var dbClient = new DbClient(sprocs);
            sprocs.CommandAsync(Arg.Any<SqlConfiguration>()).Returns(Task.FromResult(1));

            //act
            var ret = await dbClient.UpdateAsync();

            //assert
            Assert.IsTrue(ret);
            sprocs.Received(1).CommandAsync(
                    Arg.Is<SqlConfiguration>(
                        x => x.Mode == SprocMode.ExecuteNonQuery && x.StoredProcedures.Contains("UpdateAd"))
                    );
        }
Ejemplo n.º 2
0
        public async Task Get()
        {
            //arrange
            var sprocs = Substitute.For<ISqlClient>();
            var dbClient = new DbClient(sprocs);
            IEnumerable<Ad> ads = new List<Ad> { new Ad { AdID = 1 } };
            sprocs.QueryAsync(Arg.Any<SqlConfiguration>(), Arg.Any<Func<IDataReader, IEnumerable<Ad>>>()).Returns(Task.FromResult(ads));

            //act
            var ret = await dbClient.GetAsync();

            //assert
            Assert.AreEqual(1, ret.Count(x => x.AdID == 1));
            sprocs.Received(1).QueryAsync(
                    Arg.Is<SqlConfiguration>(
                        x => x.Mode == SprocMode.ExecuteReader && x.StoredProcedures.Contains(Settings.GetAd)),
                    Arg.Any<Func<IDataReader, IEnumerable<Ad>>>());
        }