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 ReceiveTest_CreateFuelIncomeOperation() { // arrange var receiver = 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>(); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; var transferOperation = Substitute.For <FuelTransferOperation>(); transferOperation.ReceiveTime = null; transferOperation.SendTime = sendTimeForReceive; transferOperation.SubdivisionFrom = subdivisionFrom; transferOperation.SubdivisionTo = subdivisionTo; transferOperation.TransferedLiters = transferedLitersForReceive; var expenseOperation = Substitute.For <FuelExpenseOperation>(); expenseOperation.FuelTransferDocument = document; expenseOperation.FuelDocument = null; expenseOperation.СreationTime = sendTimeForReceive; expenseOperation.RelatedToSubdivision = subdivisionFrom; expenseOperation.FuelLiters = transferedLitersForReceive; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.SendTime = sendTimeForReceive; document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.Sent; document.TransferedLiters = transferedLitersForReceive; document.FuelTransferOperation = transferOperation; document.FuelExpenseOperation = expenseOperation; // act document.Receive(receiver); // assert AssertsAccumulator.Create .Accumulate(() => Assert.That(document.FuelIncomeOperation.FuelTransferDocument, Is.EqualTo(document))) .Accumulate(() => Assert.That(document.FuelIncomeOperation.FuelIncomeInvoiceItem, Is.Null)) .Accumulate(() => Assert.That(document.FuelIncomeOperation.RelatedToSubdivision, Is.SameAs(document.CashSubdivisionTo))) .Accumulate(() => Assert.That(document.FuelIncomeOperation.FuelLiters, Is.EqualTo(document.TransferedLiters))) .Release(); }
public void ReceiveTest__TransferDocument_without_cashier_receiver__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>(); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; var transferOperation = Substitute.For <FuelTransferOperation>(); transferOperation.ReceiveTime = null; transferOperation.SendTime = sendTimeForReceive; transferOperation.SubdivisionFrom = subdivisionFrom; transferOperation.SubdivisionTo = subdivisionTo; transferOperation.TransferedLiters = transferedLitersForReceive; var expenseOperation = Substitute.For <FuelExpenseOperation>(); expenseOperation.FuelTransferDocument = document; expenseOperation.FuelDocument = null; expenseOperation.СreationTime = sendTimeForReceive; expenseOperation.RelatedToSubdivision = subdivisionFrom; expenseOperation.FuelLiters = transferedLitersForReceive; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.SendTime = sendTimeForReceive; document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.Sent; document.TransferedLiters = transferedLitersForReceive; document.FuelTransferOperation = transferOperation; document.FuelExpenseOperation = expenseOperation; var parameterName = document.GetType().GetMethod(nameof(document.Receive)).GetParameters()[0].Name; // act var exception = Assert.Throws <ArgumentNullException>(() => document.Receive(null)); // assert Assert.That(exception.ParamName, Is.EqualTo(parameterName)); }
public void ReceiveTest__TransferDocument_FilledCorrectly__TransferDocument_Status_Is_Received() { // arrange var receiver = 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>(); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; var transferOperation = Substitute.For <FuelTransferOperation>(); transferOperation.ReceiveTime = null; transferOperation.SendTime = sendTimeForReceive; transferOperation.SubdivisionFrom = subdivisionFrom; transferOperation.SubdivisionTo = subdivisionTo; transferOperation.TransferedLiters = transferedLitersForReceive; var expenseOperation = Substitute.For <FuelExpenseOperation>(); expenseOperation.FuelTransferDocument = document; expenseOperation.FuelDocument = null; expenseOperation.СreationTime = sendTimeForReceive; expenseOperation.RelatedToSubdivision = subdivisionFrom; expenseOperation.FuelLiters = transferedLitersForReceive; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.SendTime = sendTimeForReceive; document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.Sent; document.TransferedLiters = transferedLitersForReceive; document.FuelTransferOperation = transferOperation; document.FuelExpenseOperation = expenseOperation; // act document.Receive(receiver); // assert Assert.IsTrue(document.Status == FuelTransferDocumentStatuses.Received); }
public void ReceiveTest__TransferDocument_FuelTransferOperation_ReceiveTime_already_exists__Thrown_InvalidOperationException() { // arrange var receiver = 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>(); var document = new FuelTransferDocument(); document.FuelType = fuelTypeMock; var transferOperation = Substitute.For <FuelTransferOperation>(); transferOperation.ReceiveTime = null; transferOperation.SendTime = sendTimeForReceive; transferOperation.SubdivisionFrom = subdivisionFrom; transferOperation.SubdivisionTo = subdivisionTo; transferOperation.TransferedLiters = transferedLitersForReceive; var expenseOperation = Substitute.For <FuelExpenseOperation>(); expenseOperation.FuelTransferDocument = document; expenseOperation.FuelDocument = null; expenseOperation.СreationTime = sendTimeForReceive; expenseOperation.RelatedToSubdivision = subdivisionFrom; expenseOperation.FuelLiters = transferedLitersForReceive; document.Author = Substitute.For <Employee>(); document.Driver = Substitute.For <Employee>(); document.Car = Substitute.For <Car>(); document.SendTime = sendTimeForReceive; document.CashSubdivisionFrom = subdivisionFrom; document.CashSubdivisionTo = subdivisionTo; document.Status = FuelTransferDocumentStatuses.Sent; document.TransferedLiters = transferedLitersForReceive; document.FuelTransferOperation = transferOperation; document.FuelExpenseOperation = expenseOperation; document.FuelTransferOperation.ReceiveTime = DateTime.Now; // act, assert var exception = Assert.Throws <InvalidOperationException>(() => document.Receive(receiver)); }
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(); }
private IQueryOver <FuelTransferDocument> GetTransferDocumentQuery(IUnitOfWork uow) { FuelDocumentJournalNode resultAlias = null; FuelTransferDocument fuelTransferAlias = null; Employee authorAlias = null; Subdivision subdivisionFromAlias = null; Subdivision subdivisionToAlias = null; var fuelTransferQuery = uow.Session.QueryOver <FuelTransferDocument>(() => fuelTransferAlias) .Left.JoinQueryOver(() => fuelTransferAlias.Author, () => authorAlias) .Left.JoinQueryOver(() => fuelTransferAlias.CashSubdivisionFrom, () => subdivisionFromAlias) .Left.JoinQueryOver(() => fuelTransferAlias.CashSubdivisionTo, () => subdivisionToAlias) .SelectList(list => list .Select(() => fuelTransferAlias.Id).WithAlias(() => resultAlias.Id) .Select(() => fuelTransferAlias.CreationTime).WithAlias(() => resultAlias.CreationDate) .Select(() => fuelTransferAlias.Status).WithAlias(() => resultAlias.TransferDocumentStatus) .Select(() => fuelTransferAlias.TransferedLiters).WithAlias(() => resultAlias.Liters) .Select(() => fuelTransferAlias.Comment).WithAlias(() => resultAlias.Comment) .Select(() => fuelTransferAlias.SendTime).WithAlias(() => resultAlias.SendTime) .Select(() => fuelTransferAlias.ReceiveTime).WithAlias(() => resultAlias.ReceiveTime) .Select(() => authorAlias.Name).WithAlias(() => resultAlias.AuthorName) .Select(() => authorAlias.LastName).WithAlias(() => resultAlias.AuthorSurname) .Select(() => authorAlias.Patronymic).WithAlias(() => resultAlias.AuthorPatronymic) .Select(() => subdivisionFromAlias.Name).WithAlias(() => resultAlias.SubdivisionFrom) .Select(() => subdivisionToAlias.Name).WithAlias(() => resultAlias.SubdivisionTo) ) .OrderBy(() => fuelTransferAlias.CreationTime).Desc() .TransformUsing(Transformers.AliasToBean <FuelDocumentJournalNode <FuelTransferDocument> >()); fuelTransferQuery.Where(GetSearchCriterion( () => authorAlias.Name, () => authorAlias.LastName, () => authorAlias.Patronymic, () => fuelTransferAlias.Comment )); return(fuelTransferQuery); }
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)); }