public void SendTest__TransferDocument_FuelExpenseOperation_already_exists__Thrown_InvalidOperationException() { // arrange var cashier = Substitute.For <Employee>(); var subdivisionFrom = Substitute.For <Subdivision>(); subdivisionFrom.Id.Returns(1); var subdivisionTo = Substitute.For <Subdivision>(); subdivisionTo.Id.Returns(2); FuelType fuelTypeMock = Substitute.For <FuelType>(); IUnitOfWork uowMock = Substitute.For <IUnitOfWork>(); IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>(); fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionFrom, fuelTypeMock).Returns(50); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.New; document.TransferedLiters = transferedLitersForSend; document.FuelExpenseOperation = Substitute.For <FuelExpenseOperation>(); // act, assert Assert.Throws <InvalidOperationException>(() => document.Send(cashier, fuelRepositoryMock)); }
public void SendTest_CreateFuelTransferOperation() { // arrange var cashier = Substitute.For <Employee>(); var subdivisionFrom = Substitute.For <Subdivision>(); subdivisionFrom.Id.Returns(1); var subdivisionTo = Substitute.For <Subdivision>(); subdivisionTo.Id.Returns(2); FuelType fuelTypeMock = Substitute.For <FuelType>(); IUnitOfWork uowMock = Substitute.For <IUnitOfWork>(); IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>(); fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionFrom, fuelTypeMock).Returns(50); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.New; document.TransferedLiters = transferedLitersForSend; // act document.Send(cashier, fuelRepositoryMock); // assert AssertsAccumulator.Create .Accumulate(() => Assert.That(document.FuelTransferOperation.ReceiveTime, Is.Null)) .Accumulate(() => Assert.That(document.FuelTransferOperation.SendTime, Is.EqualTo(document.SendTime))) .Accumulate(() => Assert.That(document.FuelTransferOperation.SubdivisionFrom, Is.SameAs(document.CashSubdivisionFrom))) .Accumulate(() => Assert.That(document.FuelTransferOperation.SubdivisionTo, Is.SameAs(document.CashSubdivisionTo))) .Accumulate(() => Assert.That(document.FuelTransferOperation.TransferedLiters, Is.EqualTo(document.TransferedLiters))) .Release(); }
public void SendTest__TransferDocument_Without_Cashier__Thrown_ArgumentNullException() { // arrange var subdivisionFrom = Substitute.For <Subdivision>(); subdivisionFrom.Id.Returns(1); var subdivisionTo = Substitute.For <Subdivision>(); subdivisionTo.Id.Returns(2); FuelType fuelTypeMock = Substitute.For <FuelType>(); IUnitOfWork uowMock = Substitute.For <IUnitOfWork>(); IFuelRepository fuelRepositoryMock = Substitute.For <IFuelRepository>(); fuelRepositoryMock.GetFuelBalanceForSubdivision(uowMock, subdivisionFrom, fuelTypeMock).Returns(50); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.New; document.TransferedLiters = transferedLitersForSend; var parameterName = document.GetType().GetMethod(nameof(document.Send)).GetParameters()[0].Name; // act var exception = Assert.Throws <ArgumentNullException>(() => document.Send(null, fuelRepositoryMock)); // assert Assert.That(exception.ParamName, Is.EqualTo(parameterName)); }