예제 #1
0
        public void SessionsCollectionIsUpdatedCorrectly()
        {
            var newOpenTime = new TimeSpan(10, 0, 0);

            //set up DbSet mocks
            SetUpDbSet(new List <Instrument>());

            SetUpDbSet(new List <ExchangeSession>());

            //create exchange to be sent
            var exchange = (Exchange)_data[0].Clone(); //have to clone it, because the original is the one in the mocked context

            //remove one
            exchange.Sessions.Remove(exchange.Sessions.First());
            //change one
            exchange.Sessions.First().OpeningTime = newOpenTime;
            //add one
            exchange.Sessions.Add(new ExchangeSession {
                OpeningDay = DayOfTheWeek.Wednesday, OpeningTime = new TimeSpan(11, 0, 0), ClosingTime = new TimeSpan(15, 0, 0)
            });

            var response = Browser.Put("/exchanges", with =>
            {
                with.HttpRequest();
                with.JsonBody(exchange);
            });

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            //verify update
            ContextMock.Verify(x => x.UpdateEntryValues(
                                   It.Is <ExchangeSession>(y => y.ID == 2),
                                   It.Is <ExchangeSession>(y => y.OpeningTime == newOpenTime)));

            //verify delete
            ContextMock.Verify(x => x.SetEntryState(
                                   It.Is <ExchangeSession>(y => y.ID == 1),
                                   It.Is <EntityState>(y => y == EntityState.Deleted)));

            //verify addition
            Assert.IsTrue(_data[0].Sessions.Any(x => x.OpeningDay == DayOfTheWeek.Wednesday && x.OpeningTime == new TimeSpan(11, 0, 0)));
        }
 private void ThenActionsShouldNotBeExecuted()
 {
     ContextMock.Verify(c => c.Result1IsAsExpected(), Times.Never);
     ContextMock.Verify(c => c.Result2IsAsExpected(), Times.Never);
 }
 private void AllThenActionsShouldBeExecutedOnce()
 {
     ContextMock.Verify(c => c.Result1IsAsExpected(), Times.Once);
     ContextMock.Verify(c => c.Result2IsAsExpected(), Times.Once);
 }
 private void WhenActionShouldNotBeExecuted()
 {
     ContextMock.Verify(c => c.SomethingIsDone(), Times.Never);
 }
 private void WhenActionShouldBeExecutedOnce()
 {
     ContextMock.Verify(c => c.SomethingIsDone(), Times.Once);
 }
 private void AllGivenActionsShouldBeExecutedOnce()
 {
     ContextMock.Verify(c => c.FirstFact(), Times.Once);
     ContextMock.Verify(c => c.SecondFact(), Times.Once);
 }
 private void ExceptionChecksShouldBeExecutedOnce() =>
 ContextMock.Verify(c => c.ExceptionIsThrown(It.IsAny <Result>()), Times.Once);