Beispiel #1
0
        public void CalculateTrackRate()
        {
            DBConnection dbconn = new DBConnection();
            Rate         rate1  = new Rate()
            {
                date = DateTime.Now, fb = "asdasd123", mark = 1, soundcloud = 321321
            };

            dbconn.PostRate(rate1);
            Rate rate2 = new Rate()
            {
                date = DateTime.Now, fb = "asdasd123", mark = 3, soundcloud = 321321
            };

            dbconn.PostRate(rate2);
            Rate rate3 = new Rate()
            {
                date = DateTime.Now, fb = "asdasd123", mark = 3, soundcloud = 321321
            };

            dbconn.PostRate(rate3);

            RatesController rC  = new RatesController();
            string          asd = rC.GetTrackAverageRate(321321);

            Assert.IsTrue(!string.IsNullOrEmpty(asd) && asd.Contains("avg") && asd.Contains("sum") && asd.Contains("numberOfElements"));
        }
Beispiel #2
0
        public void RateControllerTests_MissingData(decimal rate, decimal dose, decimal vtbi)
        {
            var ctrl = new RatesController();
            var res  = ctrl.GetRates(rate, vtbi, dose);

            res.ShouldBeOfType <BadRequestObjectResult>();
        }
Beispiel #3
0
        public void RateControllerTests_GetRates(decimal rate, decimal dose, decimal vtbi, decimal expected)
        {
            var ctrl = new RatesController();
            var res  = ctrl.GetRates(rate, dose, vtbi);

            if (vtbi == 0)
            {
                vtbi = expected;
            }
            else
            {
                if (rate == 0)
                {
                    rate = expected;
                }
                else
                {
                    dose = expected;
                }
            }

            var ok = res.ShouldBeOfType <OkObjectResult>();

            var o = (JObject)JToken.FromObject(ok.Value);

            o["vtbi"].Value <decimal>().ShouldBe(vtbi);
            o["rate"].Value <decimal>().ShouldBe(rate);
            o["dose"].Value <decimal>().ShouldBe(dose);
        }
Beispiel #4
0
 public RatesControllerTest()
 {
     _logger = new RatesControllerLogerFake();
     _distributedCacheFake = new DistributedCacheFake();
     _redisRepository      = new RedisRepository(_distributedCacheFake, null);
     _ratesController      = new RatesController(_redisRepository, _logger);
 }
Beispiel #5
0
        // testing http Get (GetAllAgreements)
        public void Test_ShouldReturnEmptyAgreementsList()
        {
            var db = new TestRatesDatabaseContext();

            var ratesController = new RatesController(db);
            var result          = ratesController.GetAllAgreements() as TestDbSet <Agreement>;

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Local.Count);
        }
Beispiel #6
0
        public RatesControllerTest()
        {
            var calculator = new RatesCalculator();

            calculator.FilePath = Path.GetFullPath(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\..\..\..\carpark.api\App_Data\");

            _controller         = new RatesController(calculator);
            _controller.Request = new HttpRequestMessage();
            _controller.Request.SetConfiguration(new HttpConfiguration());
        }
Beispiel #7
0
        public async Task GetId_WhenFound_Test()
        {
            string testRateType = "USD";
            var    moq2         = new Mock <IGraphService>();
            var    moq          = new Mock <ICurrencyService>();

            moq2.Setup(call => call.GetGraphData(testRateType, "", "")).ReturnsAsync((GraphModel)null);
            moq.Setup(call => call.GetLatestRates(testRateType)).ReturnsAsync(new ResponseModel());
            var controller = new RatesController(moq.Object, moq2.Object);

            var result = await controller.Get(testRateType);

            Assert.AreEqual(typeof(OkObjectResult), result.GetType());
        }
Beispiel #8
0
        // testing http Get (GetAgreement)
        public void Test_ShouldNotReturnAgreement()
        {
            var db = new TestRatesDatabaseContext();

            Agreement agreement = TestData.GetTestAgreement1(TestData.GetTestCustomer(), TestData.GetTestBaseRate1().Code);

            db.Agreements.Add(agreement);

            Assert.AreEqual(1, db.Agreements.Local.Count);

            var ratesController = new RatesController(db);
            var httpResult      = ratesController.GetAgreement(agreement.Id++);

            Assert.IsTrue(httpResult is NotFoundResult);
        }
Beispiel #9
0
        public async Task RateWhenPendingExists()
        {
            //arrange
            RatesController ratesController = new RatesController(Mocks.GetMapper(), Mocks.GetRatesRepository(),
                                                                  Mocks.GetProductRepository(), Mocks.GetMockUserManager());

            Mocks.FillController(ratesController);

            //act
            IActionResult result = await ratesController.Rate(1);

            //assert
            Assert.AreEqual(typeof(ViewResult), result.GetType());
            ViewResult viewResult = (ViewResult)result;
        }
Beispiel #10
0
        // testing http Get (GetAgreement)
        public void Test_ShouldReturnAgreementByTheSameId()
        {
            var db = new TestRatesDatabaseContext();

            Agreement agreement = TestData.GetTestAgreement1(TestData.GetTestCustomer(), TestData.GetTestBaseRate1().Code);

            db.Agreements.Add(agreement);

            Assert.AreEqual(1, db.Agreements.Local.Count);

            var ratesController = new RatesController(db);
            var httpResult      = ratesController.GetAgreement(agreement.Id) as OkNegotiatedContentResult <Agreement>;

            Assert.IsNotNull(httpResult);
            Assert.AreEqual(agreement.Id, httpResult.Content.Id);
        }
Beispiel #11
0
        // testing http Get (GetAllAgreements)
        public void Test_ShouldReturnNotEmptyAgreementsList()
        {
            var db = new TestRatesDatabaseContext();

            var agreement1 = TestData.GetTestAgreement1(TestData.GetTestCustomer(), TestData.GetTestBaseRate1().Code);
            var agreement2 = TestData.GetTestAgreement2(TestData.GetTestCustomer(), TestData.GetTestBaseRate2().Code);

            db.Agreements.Add(agreement1);
            db.Agreements.Add(agreement2);

            var ratesController = new RatesController(db);
            var result          = ratesController.GetAllAgreements() as TestDbSet <Agreement>;

            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Local.Count);
        }
Beispiel #12
0
        public async Task IndexGet()
        {
            //arrange
            RatesController ratesController = new RatesController(Mocks.GetMapper(), Mocks.GetRatesRepository(),
                                                                  Mocks.GetProductRepository(), Mocks.GetMockUserManager());

            Mocks.FillController(ratesController);

            //act
            IActionResult result = await ratesController.Index();

            //assert
            Assert.AreEqual(typeof(ViewResult), result.GetType());
            ViewResult viewResult = (ViewResult)result;

            Assert.AreEqual(typeof(RatesViewModel), viewResult.Model.GetType());
        }
Beispiel #13
0
        // testing http Put (UpdateAgreement)
        public void Test_ShouldUpdateAgreement()
        {
            var db = new TestRatesDatabaseContext();

            var agreement = TestData.GetTestAgreement1(TestData.GetTestCustomer(), TestData.GetTestBaseRate1().Code);

            db.Agreements.Add(agreement);

            Assert.AreEqual(1, db.Agreements.Local.Count);

            // Put depends on Base Rate values
            // For that we need to add them to db

            var baseRate1 = TestData.GetTestBaseRate1();
            var baseRate2 = TestData.GetTestBaseRate2();

            db.BaseRates.Add(baseRate1);
            db.BaseRates.Add(baseRate2);

            Assert.AreEqual(2, db.BaseRates.Local.Count);

            var ratesController = new RatesController(db);

            var httpResult = ratesController.UpdateAgreement(agreement.Id, baseRate2.Code);

            // might returned either ExceptionResult, OkNegotiatedContentResult<AgreementExtended>, or NotFoundResult
            // check is required

            Assert.IsFalse(httpResult is NotFoundResult, "NotFoundResult");

            var exceptionResult = httpResult as ExceptionResult;

            if (exceptionResult != null)
            {
                throw new AssertFailedException(exceptionResult.Exception.Message);
            }
            var contentResult = httpResult as OkNegotiatedContentResult <AgreementExtended>;

            Assert.IsFalse(contentResult == null);
            Assert.AreEqual(agreement.Id, contentResult.Content.Id);
            Assert.AreEqual(baseRate2.Code, contentResult.Content.NewBaseRateType);
        }
        public void TestGetAll()
        {
            // Arrange
            var TestController = new RatesController(new RateServiceMock());

            // Execution
            var TestResult = TestController.GetRates().ToList();

            // Assertions
            Assert.True(TestResult.Count == 4, "TestResult should have received 4 rows!");
            Assert.Equal("EUR", TestResult[0].From);
            Assert.Equal("USD", TestResult[0].To);
            Assert.Equal(1.359m, TestResult[0].RateVal);
            Assert.Equal("CAD", TestResult[1].From);
            Assert.Equal("EUR", TestResult[1].To);
            Assert.Equal(0.732m, TestResult[1].RateVal);
            Assert.Equal("USD", TestResult[2].From);
            Assert.Equal("EUR", TestResult[2].To);
            Assert.Equal(0.736m, TestResult[2].RateVal);
            Assert.Equal("EUR", TestResult[3].From);
            Assert.Equal("CAD", TestResult[3].To);
            Assert.Equal(1.366m, TestResult[3].RateVal);
        }
Beispiel #15
0
        // TODO: Weird quirk with this test.
        // DateTime.Parse converts to GMT, while the model [FromBody] parser does not
        // This causes this test to fail (when it should succeed) ¯\_(ツ)_/¯
        // Quick fix would be to ignore all those pesky timezones
        // Real fix would be to accept timezones and also make rate time spans Date agnostic
        public void RateTimeTest()
        {
            List <RateDomainItem> domainItems = new List <RateDomainItem>();

            foreach (var item in rateItems)
            {
                domainItems.Add(RatesContext.CreateRateDomainItem(item));
            }

            long?result = RatesController.RateGivenTime(
                DateTimeOffset.Parse(startTime).DateTime,
                DateTimeOffset.Parse(endTime).DateTime,
                domainItems);

            Assert.Equal(1500, result);

            long?result_iOS = RatesController.RateGivenTime(
                DateTimeOffset.Parse(startTime_iOS).DateTime,
                DateTimeOffset.Parse(endTime_iOS).DateTime,
                domainItems);

            Assert.Equal(1500, result_iOS);
        }
 public RatesControllerTests()
 {
     controller = new RatesController(svc.Object);
 }
Beispiel #17
0
        // setup
        public RatesTest()
        {
            var LogFactory = LoggerFactory.Create(config => { config.AddConsole(); config.AddDebug(); config.SetMinimumLevel(LogLevel.Trace); });

            ratesController = new RatesController(LogFactory.CreateLogger <RatesController>());
        }