public void WhenSetValueCalled_ThenStoredInHttpItemsContex()
        {
            var newValue = new object();
            var storeMock = new Mock<IPerRequestStore>();
            storeMock.Setup(s => s.SetValue(It.IsAny<object>(), newValue)).Verifiable();

            var lifetimeManager = new UnityPerRequestLifetimeManager(storeMock.Object);

            lifetimeManager.SetValue(newValue);

            storeMock.Verify();
        }
        public void WhenGetValueCalled_ThenRetrievedFromHttpItemsContext()
        {
            var newValue = new object();
            var storeMock = new Mock<IPerRequestStore>();
            storeMock.Setup(s => s.GetValue(It.IsAny<object>())).Returns(newValue).Verifiable();

            var lifetimeManager = new UnityPerRequestLifetimeManager(storeMock.Object);

            lifetimeManager.SetValue(newValue);
            var returnedValue = lifetimeManager.GetValue();

            storeMock.Verify();
        }
        public void WhenValueRemoved_ThenRemovedFromContext()
        {
            var newValue = new object();
            var storeMock = new Mock<IPerRequestStore>();
            storeMock.Setup(s => s.GetValue(It.IsAny<object>())).Returns(newValue);
            storeMock.Setup(s => s.RemoveValue(It.IsAny<object>())).Verifiable();

            var lifetimeManager = new UnityPerRequestLifetimeManager(storeMock.Object);

            lifetimeManager.SetValue(newValue);
            lifetimeManager.RemoveValue();

            storeMock.Verify();
        }
        public void WhenRemovingDisposableValues_ThenDisposeInvoked()
        {
            var valueMock = new Mock<IDisposable>();
            valueMock.Setup(x => x.Dispose()).Verifiable();

            var storeMock = new Mock<IPerRequestStore>();
            storeMock.Setup(s => s.GetValue(It.IsAny<object>())).Returns(valueMock.Object);
            storeMock.Setup(s => s.RemoveValue(It.IsAny<object>())).Verifiable();

            var lifetimeManager = new UnityPerRequestLifetimeManager(storeMock.Object);

            lifetimeManager.SetValue(valueMock.Object);
            lifetimeManager.RemoveValue();

            valueMock.Verify();
        }
        public void WhenRequestEnds_ThenRemovedFromContext()
        {
            var newValue = new object();
            var storeMock = new Mock<IPerRequestStore>();
            storeMock.Setup(s => s.GetValue(It.IsAny<object>())).Returns(newValue);
            storeMock.Setup(s => s.RemoveValue(It.IsAny<Object>())).Verifiable();

            var lifetimeManager = new UnityPerRequestLifetimeManager(storeMock.Object);

            lifetimeManager.SetValue(newValue);

            storeMock.Raise(a => a.EndRequest += null, EventArgs.Empty);

            storeMock.Verify();
        }