Exemplo n.º 1
0
        public void TestDisposeCount()
        {
            var a = new MockResult("a");
            var b = (MockResult)(a.FirstChild = new MockResult("b"));
            var c = (MockResult)(a.FirstChild.FirstChild = new MockResult("b"));
            var d = (MockResult)(a.FirstChild.NextSibling = new MockResult("c"));

            var aProperties = a.Properties();
            var dProperties = d.Properties();

            var prop = aProperties ["ToString"];

            Assert.AreEqual("a", prop.ToString());

            a.Dispose();

            Assert.AreEqual(1, a.DisposeCount);
            Assert.AreEqual(1, b.DisposeCount);
            Assert.AreEqual(1, c.DisposeCount);
            Assert.AreEqual(1, d.DisposeCount);
            Assert.AreEqual("null", prop.ToString());

            Assert.Throws <NullReferenceException> (() => _ = aProperties ["ToString"]);
            Assert.Throws <NullReferenceException> (() => _ = dProperties ["ToString"]);
        }
Exemplo n.º 2
0
        public void Play()
        {
            var mb       = new SimcorpMobile("test_mobile");
            var output   = new MockResult();
            var playback = new IphoneHeadset(output);

            mb.PlayBackComponent = playback;

            mb.Play("data");

            Assert.AreEqual(output.WrittenText, "IphoneHeadset playing ");
        }
Exemplo n.º 3
0
        public void WirelessChargeCharge()
        {
            var mb           = new SimcorpMobile("test_mobile");
            var output       = new MockResult();
            var chargeDevice = new WirelessCharge(output);

            mb.ChargerDevice = chargeDevice;

            mb.Charge();

            //Assert
            Assert.AreEqual(output.WrittenText, "WirelessCharge charger");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="command">The command.</param>
        /// <param name="func">The function.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">command</exception>
        public T ExecuteCommand <T>(SqlCommand command, Func <SqlCommand, T> func)
        {
            T local2;

            if (command == null)
            {
                throw new ArgumentNullException("command");
            }
            object result = MockResult.GetResult();

            if (result != null)
            {
                return((T)result);
            }
            if (this._connection == null)
            {
                this._connection = new SqlConnection(this._connectionString);
                this._connection.Open();
                EventManager.FireConnectionOpened(this._connection);
            }
            if (this._enableTransaction && this._transaction == null)
            {
                this._transaction = this._connection.BeginTransaction();
            }
            command.Connection = this._connection;
            if (this._transaction != null)
            {
                command.Transaction = this._transaction;
            }
            object data = EventManager.FireBeforeExecute(command);

            try
            {
                T local = func(command);
                EventManager.FireAfterExecute(command, data);
                local2 = local;
            }
            catch (Exception exception)
            {
                EventManager.FireOnException(command, exception, data);
                throw;
            }
            finally
            {
                command.Connection  = null;
                command.Transaction = null;
            }
            return(local2);
        }
Exemplo n.º 5
0
            public async Task When_MockServiceGet_Then_ShouldReturnObject(string url)
            {
                // ACT
                MockResult result = await _subjectUnderTest.GetAsync <MockResult>(url);

                // ASSERT
                result.Should().NotBeNull(); // this is fluent assertions here...
                result.Id.Should().Be(1);

                // also check the 'http' call was like we expected it
                var expectedUri = new Uri(url);

                _handlerMock.Protected().Verify(
                    "SendAsync",
                    Times.Exactly(1), // we expected a single external request
                    ItExpr.Is <HttpRequestMessage>(req =>
                                                   req.Method == HttpMethod.Get && // we expected a GET request
                                                   req.RequestUri == expectedUri // to this uri
                                                   ),
                    ItExpr.IsAny <CancellationToken>()
                    );
            }
Exemplo n.º 6
0
 public void TearDown()
 {
     _mockResult = new MockResult(null);
 }