Esempio n. 1
0
        public void Mapper_ToDocument_ReturnsDocument()
        {
            // Arrange
            string currentTime = System.DateTime.Now.ToString();

            StockRespons stockResponse = new StockRespons
            {
                Name        = "STOCK",
                Price       = 123.45,
                LastUpdated = currentTime
            };

            var expectedDocument = new Document
            {
                ["Name"]        = "STOCK",
                ["Price"]       = 123.45,
                ["LastUpdated"] = currentTime
            };

            var mapper = new Mapper();

            Document result;

            // Act
            result = mapper.ToDocument(stockResponse);

            // Assert
            Assert.AreEqual(expectedDocument["Name"], result["Name"]);
            Assert.AreEqual(expectedDocument["Price"], result["Price"]);
            Assert.AreEqual(expectedDocument["LastUpdated"], result["LastUpdated"]);
        }
Esempio n. 2
0
        public void Mapper_ToStockContract_ReturnsStockResponse()
        {
            // Arrange
            string currentTime = System.DateTime.Now.ToString();
            var    item        = new Document
            {
                ["Name"]        = "STOCK",
                ["Price"]       = 123.45,
                ["LastUpdated"] = currentTime
            };

            var mapper = new Mapper();

            StockRespons expectedResponse = new StockRespons
            {
                Name        = "STOCK",
                Price       = 123.45,
                LastUpdated = currentTime
            };

            StockRespons result;

            // Act
            result = mapper.ToStockContract(item);

            // Assert
            Assert.AreEqual(expectedResponse.Name, result.Name);
            Assert.AreEqual(expectedResponse.Price, result.Price);
            Assert.AreEqual(expectedResponse.LastUpdated, result.LastUpdated);
        }
Esempio n. 3
0
        public void Mapper_ToStockContract_ReturnsStocks()
        {
            // Arrange
            string currentTime = System.DateTime.Now.ToString();

            var item1 = new Document();

            item1["Name"]        = "STOCK1";
            item1["Price"]       = 123.45;
            item1["LastUpdated"] = currentTime;

            var item2 = new Document();

            item2["Name"]        = "STOCK2";
            item2["Price"]       = 111.11;
            item2["LastUpdated"] = currentTime;

            List <Document> itemList = new List <Document>();

            itemList.Add(item1);
            itemList.Add(item2);

            StockRespons expectedItem1 = new StockRespons();

            expectedItem1.Name        = "STOCK1";
            expectedItem1.Price       = 123.45;
            expectedItem1.LastUpdated = currentTime;

            StockRespons expectedItem2 = new StockRespons();

            expectedItem2.Name        = "STOCK2";
            expectedItem2.Price       = 111.11;
            expectedItem2.LastUpdated = currentTime;

            List <StockRespons> expectedItemList = new List <StockRespons>
            {
                expectedItem1,
                expectedItem2
            };

            var mapper = new Mapper();

            IEnumerable <StockRespons> result;

            // Act
            result = mapper.ToStockContract(itemList);

            // Assert
            var enumerator = result.GetEnumerator();
            int count      = -1;

            while (enumerator.MoveNext())
            {
                count++;
                Assert.AreEqual(expectedItemList[count].Name, enumerator.Current.Name);
                Assert.AreEqual(expectedItemList[count].Price, enumerator.Current.Price);
                Assert.AreEqual(expectedItemList[count].LastUpdated, enumerator.Current.LastUpdated);
            }
        }
Esempio n. 4
0
        public void ConsumeMessage([FromBody] StockRespons stock)
        {
            _stockServer.UpdateStock(stock);
            SendSMS send = new SendSMS();

            send.InitializeSMS();
            send.sendSMS("PATCHED", stock.Name.ToString(), stock.Price.ToString());
        }
Esempio n. 5
0
 public Document ToDocumentMode(StockRespons stock)
 {
     return(new Document {
         ["Name"] = stock.Name,
         ["Price"] = stock.Price,
         ["LastUpdated"] = DateTime.UtcNow.ToString()
     });
 }
Esempio n. 6
0
        public void ConsumeMessage([FromBody] StockRespons stock)
        {
            _stockServer.AddStock(stock);
            SendSMS send = new SendSMS();

            send.InitializeSMS();
            send.sendSMS("ADDED", stock.Name.ToString());
        }
Esempio n. 7
0
 public Document ToDocument(StockRespons stock)
 {
     return(new Document
     {
         ["Name"] = stock.Name,
         ["Price"] = stock.Price,
         ["LastUpdated"] = stock.LastUpdated
     });
 }
Esempio n. 8
0
        public void GetAllFromDatabase_ReturnResponce()
        {
            // Arrange
            // Create sample data
            var testData = new StockRespons
            {
                Name        = "test-Stock",
                Price       = 1000,
                LastUpdated = "09/04/2020 10:36:52"
            };

            // Act
            // Test if mapper returns
            var result = _mapper.ToDocument(testData);

            // Assert

            Assert.IsNotNull(result);
        }
Esempio n. 9
0
        public void DeleteStocks_SeeAdded()
        {
            // Arrange
            // Create sample data

            var testData = new StockRespons
            {
                Name        = "test-Stock",
                Price       = 1000,
                LastUpdated = "09/04/2020 10:36:52"
            };

            // Act
            // Test if mapper returns

            var response = _mapper.ToDocument(testData);

            // Assert

            Assert.IsNotNull(response);
        }
Esempio n. 10
0
        public async Task <IActionResult> AddNewStocks([FromBody] StockRespons stockRequest)
        {
            await _stockServer.AddStock(stockRequest);

            return(Ok());
        }
Esempio n. 11
0
 public async Task UpdateStock(StockRespons stock)
 {
     var stockIn = _mapper.ToDocument(stock);
     await _stockRepository.UpdateStock(stockIn);
 }