示例#1
0
        public async Task Put_UpdateLastHourlySharePrice_NotExist_NotFoundResult()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2019, 04, 07, 5, 0, 0)
            };

            HourlyShareRate ret = null;

            _shareServiceMock.Setup(t => t.UpdateLastPriceAsync(hourRate.Symbol, hourRate.Rate))
            .Returns(Task.FromResult(ret));

            // Act
            var result = await _shareController.UpdateLastPrice(hourRate.Symbol, hourRate.Rate);

            // Assert
            Assert.NotNull(result);

            var notFoundResult = result as NotFoundResult;

            Assert.AreEqual(404, notFoundResult.StatusCode);
        }
示例#2
0
        public async Task Post_ShouldInsertHourlySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2019, 04, 07, 5, 0, 0)
            };

            _shareServiceMock.Setup(t => t.InsertAsync(Map(hourRate)))
            .Returns(Task.FromResult(0));

            // Act
            var result = await _shareController.Post(hourRate);

            // Assert
            Assert.NotNull(result);

            // TODO: This unit test is broken, the result received from the Post method is correct.
            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode); //This is the FIX
        }
        public async Task Post_ShouldInsertHourlySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2018, 08, 17, 5, 0, 0)
            };

            // Act
            var result = await _shareController.Post(hourRate);

            // Assert
            Assert.NotNull(result);

            // TODO: This unit test is broken, the result received from the Post method is correct.
            // => Fixed and added appropriate assertions
            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
            Assert.AreEqual(201, createdResult.StatusCode);
            var responseObject = createdResult.Value as HourlyShareRateModel;

            Assert.NotNull(responseObject);
            Assert.AreEqual("CBI", responseObject.Symbol);
            Assert.AreEqual(330.0M, responseObject.Rate);
            Assert.IsTrue(DateTime.Equals(hourRate.TimeStamp, responseObject.TimeStamp));
        }
示例#4
0
 private HourlyShareRate Map(HourlyShareRateModel rate)
 {
     return(new HourlyShareRate()
     {
         Id = rate.Id,
         TimeStamp = rate.TimeStamp,
         Rate = rate.Rate,
         Symbol = rate.Symbol
     });
 }
示例#5
0
        public async Task <IActionResult> Post([FromBody] HourlyShareRateModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var hourlyShareRate = Map(value);
            await _shareService.InsertAsync(hourlyShareRate);

            return(Created($"Share/{hourlyShareRate.Id}", Map(hourlyShareRate)));
        }
        public async Task Post_ShouldReturnBadRequestHourlySharePrice()
        {
            HourlyShareRateModel hourRate = null;

            // Arrange

            // Act
            var result = await _shareController.Post(hourRate);

            // Assert
            var returnResult = result as BadRequestObjectResult;

            Assert.IsInstanceOf(typeof(BadRequestObjectResult), returnResult);
        }
示例#7
0
        public async Task <IActionResult> Post([FromBody] HourlyShareRateModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var hourlyShareRate = Map(value);

            //BUG: The team noticed that sometimes there are duplicate records for the hourly rate.
            //await _shareService.InsertAsync(hourlyShareRate);
            //FIX [Immi]
            await _shareService.InserttHourlyPriceAsync(hourlyShareRate);

            return(Created($"Share/{hourlyShareRate.Id}", Map(hourlyShareRate)));
        }
示例#8
0
        public async Task <IActionResult> Put([FromBody] HourlyShareRateModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var hourlyShareRate = Map(value);
            var rest            = await _shareService.UpsertHourlyPriceAsync(hourlyShareRate);

            if (rest == 200)
            {
                return(Ok(Map(hourlyShareRate)));
            }
            return(Created($"Share/{hourlyShareRate.Id}", Map(hourlyShareRate)));
        }
示例#9
0
        public async Task Post_SupplyIncorrectModel_ShouldReturnBadRequest()
        {
            var hourRate = new HourlyShareRateModel
            {
                Rate      = 330.0M,
                TimeStamp = new DateTime(2018, 08, 17, 5, 0, 0)
            };

            _shareController.ModelState.AddModelError("error", "Share symbol should be all capital letters with 3 characters");

            var act = await _shareController.Post(hourRate);

            var result = act as BadRequestObjectResult;

            Assert.IsNotNull(result);
        }
示例#10
0
        public async Task Post_ShouldInsertHourlySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2018, 01, 16, 14, 5, 0)
            };

            // Act
            var result = await _shareController.Post(hourRate);

            Assert.NotNull(result);

            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
        }
示例#11
0
        public async Task <IActionResult> Post([FromBody] HourlyShareRateModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var existing = await _shareService.GetHourlyAsync(value.Symbol, value.TimeStamp);

            if (existing != null)
            {
                return(BadRequest($"Hourly rate already exits for {value.Symbol} at {value.TimeStamp}"));
            }

            var hourlyShareRate = Map(value);
            await _shareService.InsertAsync(hourlyShareRate);

            return(Created($"Share/{hourlyShareRate.Id}", Map(hourlyShareRate)));
        }
示例#12
0
        public async Task <IActionResult> Post([FromBody] HourlyShareRateModel model)
        {
            if (!ModelState.IsValid || model == null)
            {
                return(BadRequest(ModelState));
            }

            HourlyShareRate share = new HourlyShareRate
            {
                Rate      = model.Rate,
                Symbol    = model.Symbol,
                TimeStamp = model.TimeStamp
            };


            await _shareRepository.InsertAsync(share);

            return(Created($"Share/{share.Id}", share));
        }
示例#13
0
        public async Task Post_ShouldInsertDailySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2018, 01, 16, 14, 5, 0)
            };

            // Act
            var result = await _shareController.Post(hourRate);

            // Assert
            Assert.NotNull(result);

            // TODO: This unit test is broken, the result received from the Post method is correct.
            var createdResult = result as CreatedResult;

            Assert.NotNull(createdResult);
        }
示例#14
0
        public async Task Put_ShouldUpdateLastHourlySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2019, 04, 07, 5, 0, 0)
            };

            _shareServiceMock.Setup(t => t.UpdateLastPriceAsync(hourRate.Symbol, hourRate.Rate))
            .Returns(Task.FromResult(Map(hourRate)));

            // Act
            var result = await _shareController.UpdateLastPrice(hourRate.Symbol, hourRate.Rate);

            // Assert
            Assert.NotNull(result);
            var okresult = result as OkObjectResult;

            Assert.AreEqual(200, okresult.StatusCode);
        }
        public async Task <IActionResult> Post([FromBody] HourlyShareRateModel value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var hourlyrate = await _shareService.GetHourlyAsync(value.Symbol, value.TimeStamp);

            if (hourlyrate != null)
            {
                var hourlyShareRate = Map(value);
                await _shareService.InsertAsync(hourlyShareRate);

                return(Created($"Share/{hourlyShareRate.Id}", Map(hourlyShareRate)));
            }
            else
            {
                hourlyrate.Rate = value.Rate;
                await _shareService.UpdateAsync(hourlyrate);

                return(Ok("updated"));
            }
        }
示例#16
0
        public async Task Put_ShouldUpsertHourlySharePrice()
        {
            // Arrange
            var hourRate = new HourlyShareRateModel
            {
                Symbol    = "CBI",
                Rate      = 330.0M,
                TimeStamp = new DateTime(2019, 04, 07, 5, 0, 0)
            };

            _shareServiceMock.Setup(t => t.UpsertHourlyPriceAsync(Map(hourRate)))
            .Returns(Task.FromResult(new Random().Next(200, 201)));

            // Act
            var result = await _shareController.Post(hourRate);

            // Assert
            Assert.NotNull(result);

            var createdResult = result as CreatedResult;
            var okresult      = result as OkObjectResult;

            Assert.True(((createdResult != null && createdResult.StatusCode == 201) || (okresult != null && okresult.StatusCode == 200)), "Put Used to Insert or Update the Hourly Price");
        }