예제 #1
0
        public async Task ReturnNothingWhenNothingIsGivenAsTheRechercheCriteria()
        {
            // mock prep
            var mockService = new Mock <ISuggestionService>();

            // Declaration and call to the controller
            var        controller = new SuggestionsController(mockService.Object);
            JsonResult result     = await controller.Get();

            // Tests
            Assert.IsType <Suggestions>(result.Value);

            Suggestions resultObject = (Suggestions)result.Value;

            Assert.Equal(0, resultObject.ListSuggestion.Count);
        }
예제 #2
0
        public async Task ReturnSomethingWhateverWeGive(string dataFromTheory)
        {
            // variables used for the MOCK
            var search = new Search(dataFromTheory);

            search.Latitude  = 0m;
            search.Longitude = 0m;

            var suggestions = new Suggestions();

            suggestions.ListSuggestion = new List <Suggestions.Suggestion>();

            suggestions.ListSuggestion.Add(new Suggestions.Suggestion {
                Name      = "wordwithana",
                Latitude  = "1.1",
                Longitude = "1.1",
                Score     = 1
            });

            // Configure the mock of the service to return what we want for the test
            // TODO: Doesnt work now, GetLocations is not overloaded, locations return nothing
            // and crashs the test
            var mockService = new Mock <ISuggestionService>();

            mockService.Setup(repo => repo.GetSuggestions(search))
            .Returns(Task.FromResult(suggestions));

            // Declaration and call to the controller
            var        controller = new SuggestionsController(mockService.Object);
            JsonResult result     = await controller.Get(dataFromTheory);

            // tests
            Assert.IsType <Suggestions>(result.Value);

            Suggestions resultObject = (Suggestions)result.Value;

            Assert.Equal(1, resultObject.ListSuggestion.Count);
        }
예제 #3
0
        public void WhenUserAcceptPayment_MerchantWebPageIsNotified()
        {
            //arrange
            var productCatalogMoq = new Mock <IProductCatalog>();
            var products          = new List <Product>()
            {
                new Product()
                {
                    ProductId = "1", Name = "Name1", Price = 11.11m
                },
                new Product()
                {
                    ProductId = "2", Name = "Name2", Price = 22.22m
                },
            };

            productCatalogMoq.Setup(x => x.GetProductsForCompany(It.IsAny <string>())).Returns(
                products);
            productCatalogMoq.Setup(x => x.GetProduct(It.IsAny <string>(), It.Is <string>(s => s == "1"))).Returns(products[0]);

            var suggestionController = new SuggestionsController(productCatalogMoq.Object);

            var transactionSystemMoq = new Mock <ITransactionSystem>();
            var definedTransactionId = Guid.NewGuid().ToString();

            transactionSystemMoq.Setup(x => x.RegisterTransaction(It.IsAny <Product>())).Returns(definedTransactionId);
            transactionSystemMoq.Setup(x => x.AuthTransaction(It.IsAny <TransactionAuth>())).Returns(products.First());
            var prepareController      = new PaymentPrepareController(transactionSystemMoq.Object, productCatalogMoq.Object);
            var merchantNotifierMoq    = new Mock <IMerchantNotifier>();
            var intermediateController = new PaymentFinalController(transactionSystemMoq.Object,
                                                                    merchantNotifierMoq.Object);

            var beaconId = "beacon_Id";

            //act
            var list          = suggestionController.Get(beaconId);
            var transactionId = prepareController.Get(list.First().ProductId);

            intermediateController.Post(new TransactionAuth()
            {
                TransactionId = transactionId, AuthCode = "1234"
            });

            //assert
            Assert.AreEqual(definedTransactionId, transactionId);
            productCatalogMoq.Verify(
                x => x.GetProductsForCompany(It.Is <string>(passedBeaconId => passedBeaconId.Equals(beaconId))),
                Times.Once);

            transactionSystemMoq.Verify(
                x => x.RegisterTransaction(It.Is <Product>(product => product.ProductId == "1" && product.Price == 11.11m)),
                Times.Once);
            transactionSystemMoq.Verify(
                x =>
                x.AuthTransaction(
                    It.Is <TransactionAuth>(
                        auth => auth.TransactionId == definedTransactionId && auth.AuthCode == "1234")), Times.Once);

            merchantNotifierMoq.Verify(
                x =>
                x.NotifyMerchant(
                    It.Is <MerchantNotificationMessage>(
                        msg => msg.TransactionId == definedTransactionId && msg.ProductId == "1")), Times.Once);
        }