コード例 #1
0
        public void PrintReceiptShouldCoverAllSteps()
        {
            using (Sequence.Create())
            {
                _fiscalPrinterMock
                .Setup(x => x.Connect())
                .InSequence()
                .Returns(true);
                _fiscalPrinterMock
                .Setup(x => x.StartReceipt(It.IsAny <int>()))
                .InSequence();
                _fiscalPrinterMock
                .Setup(x => x.SellArticle(It.IsAny <Article>()))
                .InSequence(Times.Exactly(_receipt.Articles.Count))
                .Returns(true);
                _fiscalPrinterMock
                .Setup(x => x.EndReceipt())
                .InSequence();

                var facade = new PrinterFacade(_fiscalPrinterMock.Object, new PrinterConfiguration(), PrinterType.Elzab);
                facade.PrintReceipt(_receipt);
            }

            _fiscalPrinterMock.VerifyAll();
        }
コード例 #2
0
        public void FacadeShouldNotifyOfPrintReceipt()
        {
            var observerMock = new Mock <IObserver <PrinterInfo> >(MockBehavior.Strict);

            observerMock
            .Setup(x => x.OnNext(It.IsAny <PrinterInfo>()))
            .Callback <PrinterInfo>(x =>
            {
                Assert.AreEqual(x.operationType, OperationType.Printed);
            });

            var fiscalPrinterMock = new Mock <IFiscalPrinter>(MockBehavior.Strict);

            fiscalPrinterMock
            .Setup(x => x.Connect())
            .Returns(true);
            fiscalPrinterMock
            .Setup(x => x.StartReceipt(It.IsAny <int>()));
            fiscalPrinterMock
            .Setup(x => x.SellArticle(It.IsAny <Article>()))
            .Returns(true);
            fiscalPrinterMock
            .Setup(x => x.EndReceipt());

            var facade = new PrinterFacade(fiscalPrinterMock.Object, new PrinterConfiguration(), PrinterType.Posnet);

            facade.Subscribe(observerMock.Object);
            facade.PrintReceipt(new Receipt
            {
                Articles = new List <Article>()
            });

            observerMock.Verify(x => x.OnNext(It.IsAny <PrinterInfo>()), Times.Once());
        }