Beispiel #1
0
        public void OddSaveUpdate_valid_input()
        {
            // Arrange: Setup all o\objects
            var mockRepo = new Mock <IOddRepository>();
            var data     = mockRepo.Setup(x => x.SaveUpdateOdd(It.IsAny <Odd>())).Returns(1);

            var           mockloggerRepo = new Mock <ILogger>();
            var           loggerdata     = mockloggerRepo.Setup(x => x.Log(It.IsAny <string>(), It.IsAny <string>()));
            OddController controller     = new OddController(mockRepo.Object, mockloggerRepo.Object)
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act: Save the Odd
            OddsModel           model  = new OddsModel();
            HttpResponseMessage result = controller.SaveUpdateOdd(model);

            // Verify the method was called
            mockloggerRepo.Verify(m => m.Log(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(0));

            mockRepo.Verify(x => x.SaveUpdateOdd(It.IsAny <Odd>()), Times.Exactly(1));

            // Assert:
            Assert.IsNotNull(result);
            Assert.AreNotEqual(0, result);
        }
Beispiel #2
0
        public void GetOddbyId_Id_equals_0()
        {
            // Arrange: Setup all o\objects
            var mockRepo = new Mock <IOddRepository>();
            var data     = mockRepo.Setup(x => x.GetbyId(It.IsAny <int>())).Returns(new Odd());

            var           mockloggerRepo = new Mock <ILogger>();
            var           loggerdata     = mockloggerRepo.Setup(x => x.Log(It.IsAny <string>(), It.IsAny <string>()));
            OddController controller     = new OddController(mockRepo.Object, mockloggerRepo.Object)
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act: Save the Odd
            OddsModel model = new OddsModel();

            model.Id = 0;
            HttpResponseMessage result = controller.GetOddById(model);

            // Verify the method was called
            mockloggerRepo.Verify(m => m.Log(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(0));

            mockRepo.Verify(x => x.GetbyId(It.IsAny <int>()), Times.Exactly(1));

            // Assert:
            Assert.IsNotNull(result);

            Assert.AreEqual(System.Net.HttpStatusCode.OK, result.StatusCode);
        }
Beispiel #3
0
        /// <summary>
        /// Add Odds data into Messaging queue using RabbitMQ
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public void PostOddDetails(OddsModel model
                                   )
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "oddsqueue",
                                         durable: false,
                                         exclusive: false,
                                         autoDelete: false,
                                         arguments: null);

                    string message = JsonConvert.SerializeObject(model);
                    var    body    = Encoding.UTF8.GetBytes(message);
                    channel.BasicPublish(exchange: "",
                                         routingKey: "oddsqueue",
                                         basicProperties: null,
                                         body: body);
                }
        }
Beispiel #4
0
 public HttpResponseMessage GetOddById(OddsModel model)
 {
     try
     {
         Odd odd = _repo.GetbyId(model.Id);
         return(Request.CreateResponse(HttpStatusCode.OK, odd));
     }
     catch (Exception ex)
     {
         _loggerrepo.Log(ex.Message, ex.StackTrace);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Beispiel #5
0
 public HttpResponseMessage DeleteOdd(OddsModel model)
 {
     try
     {
         var result = _repo.DeleteOdd(model.Id);
         PostOddDetails(model);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     catch (Exception ex)
     {
         _loggerrepo.Log(ex.Message, ex.StackTrace);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Beispiel #6
0
        public ActionResult Odds(int sportId, int eventId)
        {
            IPinnacleApi pinnacle = new PinnacleApi(_token);
            OddsModel    odds     = pinnacle.GetOddsForEvent(sportId, eventId);

            OddsViewModel oddsVms = _mapper.Map <OddsViewModel>(odds);

            if (oddsVms != null)
            {
                return(View(oddsVms));
            }
            else
            {
                return(View("NoData"));
            }
        }
Beispiel #7
0
 public HttpResponseMessage SaveUpdateOdd(OddsModel model)
 {
     try
     {
         Odd odd = new Odd();
         odd.Description = model.Description;
         odd.Odd_1       = Convert.ToDecimal(model.Odd_1);
         odd.Odd_X       = Convert.ToDecimal(model.Odd_X);
         odd.Odd_2       = Convert.ToDecimal(model.Odd_2);
         odd.Id          = model.Id;
         var result = _repo.SaveUpdateOdd(odd);
         model.Id = result;
         PostOddDetails(model);
         return(Request.CreateResponse(HttpStatusCode.OK, result));
     }
     catch (Exception ex)
     {
         _loggerrepo.Log(ex.Message, ex.StackTrace);
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Beispiel #8
0
        public void OddSaveUpdate_repo_is_null()
        {
            // Arrange: Setup all o\objects
            var mockRepo = new Mock <IOddRepository>();
            var data     = mockRepo.Setup(x => x.SaveUpdateOdd(It.IsAny <Odd>())).Returns(0);

            var           mockloggerRepo = new Mock <ILogger>();
            var           loggerdata     = mockloggerRepo.Setup(x => x.Log(It.IsAny <string>(), It.IsAny <string>()));
            OddController controller     = new OddController(null, mockloggerRepo.Object)
            {
                Request       = new System.Net.Http.HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };

            // Act: Save the Odd
            OddsModel           model  = new OddsModel();
            HttpResponseMessage result = controller.SaveUpdateOdd(model);

            // Assert:
            Assert.IsNotNull(result);
            Assert.AreEqual(System.Net.HttpStatusCode.InternalServerError, result.StatusCode);

            mockloggerRepo.Verify(m => m.Log(It.IsAny <string>(), It.IsAny <string>()), Times.Exactly(1));
        }
Beispiel #9
0
        public HttpResponseMessage GetAllOdds()
        {
            OddsModel data    = new OddsModel();
            var       factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            connection = factory.CreateConnection();
            channel    = connection.CreateModel();
            channel.QueueDeclare(queue: "oddsqueue", durable: false, exclusive: false, autoDelete: false, arguments: null);

            var consumer = new EventingBasicConsumer(channel);

            consumer.Received += (model, ea) =>
            {
                var body         = ea.Body;
                var message      = Encoding.UTF8.GetString(body);
                var deserialized = JsonConvert.DeserializeObject <OddsModel>(message);

                data = new OddsModel
                {
                    Description = deserialized.Description,
                    Odd_1       = deserialized.Odd_1,
                    Odd_X       = deserialized.Odd_X,
                    Odd_2       = deserialized.Odd_2,
                    Id          = deserialized.Id
                };

                OddsHub.BroadcastData(data);

                // Display message
            };
            channel.BasicConsume(queue: "oddsqueue", autoAck: true, consumer: consumer);
            return(Request.CreateResponse(HttpStatusCode.OK, data));
        }
Beispiel #10
0
        public static void BroadcastData(OddsModel model)
        {
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext <OddsHub>();

            context.Clients.All.updatedData(model);
        }