public void execute_throws_concurrency_exception_when_versions_dont_match( Envelope<Ticket> ticket, TicketDetails existingTicket, Mock<IQuery<Guid, TicketDetails>> getTicketQuery, Mock<ICommand<Ticket>> inner) { getTicketQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(t => t.Item == ticket.Item.TicketId))) .Returns(existingTicket); var sut = new TicketConcurrentUpdatesDetector<Ticket>(inner.Object, getTicketQuery.Object); sut.Invoking(cmd => cmd.Execute(ticket)).ShouldThrow<OptimisticConcurrencyException>(); }
public void execute_call_inner_command( Envelope<Ticket> ticket, TicketDetails existingTicket, Mock<IQuery<Guid, TicketDetails>> getTicketQuery, Mock<ICommand<Ticket>> inner) { existingTicket.Version = ticket.Item.ExpectedVersion; getTicketQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(t => t.Item == ticket.Item.TicketId))) .Returns(existingTicket); var sut = new TicketConcurrentUpdatesDetector<Ticket>(inner.Object, getTicketQuery.Object); sut.Execute(ticket); inner.Verify(c => c.Execute(ticket), Times.Once); }
public void put_returns_200_ok_with_correct_etag_on_success( Guid ticketId, TicketModel ticket, TicketDetails ticketDetails, [Frozen]Mock<IUserNameQuery> userQuery, [Frozen]Mock<IQuery<Guid, TicketDetails>> ticketQuery, TicketsController sut) { ticketQuery.Setup(q => q.Execute(It.IsAny<Envelope<Guid>>())).Returns(ticketDetails); var actual = sut.Put(ticketId, ticket); actual.Should().BeOfType<OkResultWithETag<TicketResponseModel>>() .Which.ETagValue.Should().Be(ticketDetails.Version.ToString()); }
public void post_returns_ticket_etag_on_success( TicketModel ticket, TicketDetails ticketDetails, [Frozen]Mock<IQuery<Guid, TicketDetails>> ticketQuery, [Frozen]Mock<UrlHelper> url, TicketsController sut) { var createdUri = "http://localhost:8051/api/tickets/123"; url.Setup(u => u.Link(It.IsAny<string>(), It.IsAny<object>())) .Returns(createdUri); ticketQuery.Setup(q => q.Execute(It.IsAny<Envelope<Guid>>())).Returns(ticketDetails); var actual = sut.Post(ticket); actual.Should().BeOfType<CreatedResultWithETag<TicketResponseModel>>() .Which.ETagValue.Should().Be(ticketDetails.Version.ToString()); }
public void post_returns_created_ticket_on_success( TicketModel ticket, TicketDetails ticketDetails, [Frozen]Mock<IQuery<Guid, TicketDetails>> ticketQuery, [Frozen]Mock<UrlHelper> url, TicketsController sut) { var createdUri = "http://localhost:8051/api/tickets/123"; url.Setup(u => u.Link(It.IsAny<string>(), It.IsAny<object>())) .Returns(createdUri); ticketQuery.Setup(q => q.Execute(It.IsAny<Envelope<Guid>>())).Returns(ticketDetails); var actual = sut.Post(ticket); actual.Should().BeOfType<CreatedResultWithETag<TicketResponseModel>>() .Which.Content.ShouldBeEquivalentTo(ticketDetails, options => options.ExcludingMissingMembers()); }
public void get_by_id_returns_ticket_version_in_etag_header( Guid ticketId, TicketDetails ticket, [Frozen]Mock<IQuery<Guid, TicketDetails>> ticketQuery, TicketsController sut) { ticketQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(t => t.Item == ticketId))).Returns(ticket); var actual = sut.Get(ticketId); actual.Should().BeOfType<OkResultWithETag<TicketResponseModel>>() .Which.ETagValue.Should().Be(ticket.Version.ToString()); }
public void get_by_id_returns_ticket_returned_by_query( string userName, Guid ticketId, TicketDetails ticket, [Frozen]Mock<IQuery<Guid, TicketDetails>> ticketQuery, TicketsController sut) { ticketQuery.Setup(q => q.Execute(It.Is<Envelope<Guid>>(t => t.Item == ticketId))).Returns(ticket); var actual = sut.Get(ticketId); actual.Should().BeOfType<OkResultWithETag<TicketResponseModel>>() .Which.Content.Should().ShouldBeEquivalentTo(ticket, options => options.ExcludingMissingMembers()); }