Exemple #1
0
        public void ValidateContentNegotiatorShouldThrowExceptionIfContentValidatorIsNotCorrect()
        {
            var actionResultWithContentNegotiator = new OkNegotiatedContentResult <int>(5, MyWebApi.Controller <WebApiController>().AndProvideTheController());

            ContentNegotiatorValidator.ValidateContentNegotiator(
                actionResultWithContentNegotiator,
                new CustomContentNegotiator(),
                TestObjectFactory.GetFailingValidationAction());
        }
        public void MWQMSampleLanguage_Controller_Put_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMSampleLanguageController mwqmSampleLanguageController = new MWQMSampleLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmSampleLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmSampleLanguageController.DatabaseType);

                    MWQMSampleLanguage mwqmSampleLanguageLast = new MWQMSampleLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;

                        MWQMSampleLanguageService mwqmSampleLanguageService = new MWQMSampleLanguageService(query, db, ContactID);
                        mwqmSampleLanguageLast = (from c in db.MWQMSampleLanguages select c).FirstOrDefault();
                    }

                    // ok with MWQMSampleLanguage info
                    IHttpActionResult jsonRet = mwqmSampleLanguageController.GetMWQMSampleLanguageWithID(mwqmSampleLanguageLast.MWQMSampleLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMSampleLanguage> Ret = jsonRet as OkNegotiatedContentResult <MWQMSampleLanguage>;
                    MWQMSampleLanguage mwqmSampleLanguageRet           = Ret.Content;
                    Assert.AreEqual(mwqmSampleLanguageLast.MWQMSampleLanguageID, mwqmSampleLanguageRet.MWQMSampleLanguageID);

                    BadRequestErrorMessageResult badRequest = jsonRet as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest);

                    // Put to return success
                    IHttpActionResult jsonRet2 = mwqmSampleLanguageController.Put(mwqmSampleLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMSampleLanguage> mwqmSampleLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMSampleLanguage>;
                    Assert.IsNotNull(mwqmSampleLanguageRet2);

                    BadRequestErrorMessageResult badRequest2 = jsonRet2 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest2);

                    // Put to return CSSPError because MWQMSampleLanguageID of 0 does not exist
                    mwqmSampleLanguageRet.MWQMSampleLanguageID = 0;
                    IHttpActionResult jsonRet3 = mwqmSampleLanguageController.Put(mwqmSampleLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    OkNegotiatedContentResult <MWQMSampleLanguage> mwqmSampleLanguageRet3 = jsonRet3 as OkNegotiatedContentResult <MWQMSampleLanguage>;
                    Assert.IsNull(mwqmSampleLanguageRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest3);
                }
            }
        }
        public void ValidateContentNegotiatorShouldThrowExceptionIfContentValidatorIsNotCorrect()
        {
            var actionResultWithContentNegotiator = new OkNegotiatedContentResult<int>(5, MyWebApi.Controller<WebApiController>().AndProvideTheController());

            ContentNegotiatorValidator.ValidateContentNegotiator(
                actionResultWithContentNegotiator,
                new CustomContentNegotiator(),
                TestObjectFactory.GetFailingValidationAction());
        }
        public void GetOrderBookTest_ChecksIfOrderBookIsRetreivedProperly_ValidatesReturnedOrderBook()
        {
            // Get the context
            // IApplicationContext applicationContext = ContextRegistry.GetContext();

            // Get the instance through Spring configuration
            MarketController marketController = (MarketController)_applicationContext["MarketController"];
            LimitOrderBook   limitOrderBook   = new LimitOrderBook("XBTUSD");

            Order buyOrder1 = OrderFactory.CreateOrder("1233", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                       Constants.ORDER_SIDE_BUY, 150, 481.34M, new StubbedOrderIdGenerator());
            Order buyOrder2 = OrderFactory.CreateOrder("1234", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                       Constants.ORDER_SIDE_BUY, 50, 482.34M, new StubbedOrderIdGenerator());
            Order buyOrder3 = OrderFactory.CreateOrder("1222", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                       Constants.ORDER_SIDE_BUY, 50, 483.34M, new StubbedOrderIdGenerator());
            Order sellOrder1 = OrderFactory.CreateOrder("1233", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                        Constants.ORDER_SIDE_SELL, 150, 491.34M, new StubbedOrderIdGenerator());
            Order sellOrder2 = OrderFactory.CreateOrder("1234", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                        Constants.ORDER_SIDE_SELL, 50, 492.34M, new StubbedOrderIdGenerator());
            Order sellrder3 = OrderFactory.CreateOrder("1222", "XBTUSD", Constants.ORDER_TYPE_LIMIT,
                                                       Constants.ORDER_SIDE_SELL, 50, 493.34M, new StubbedOrderIdGenerator());

            limitOrderBook.PlaceOrder(buyOrder1);
            limitOrderBook.PlaceOrder(buyOrder2);
            limitOrderBook.PlaceOrder(buyOrder3);
            limitOrderBook.PlaceOrder(sellOrder1);
            limitOrderBook.PlaceOrder(sellOrder2);
            limitOrderBook.PlaceOrder(sellrder3);

            OrderBookMemoryImage orderBookMemoryImage = (OrderBookMemoryImage)_applicationContext["OrderBookMemoryImage"];

            orderBookMemoryImage.OnOrderBookChanged(limitOrderBook);
            IHttpActionResult httpActionResult = marketController.GetOrderBook("XBTUSD");

            OkNegotiatedContentResult <object> okResponseMessage =
                (OkNegotiatedContentResult <object>)httpActionResult;
            OrderBookRepresentation representation = okResponseMessage.Content as OrderBookRepresentation;

            Assert.IsNotNull(okResponseMessage);
            Assert.IsNotNull(representation);
            // Check the Currency Pair for Bid Book
            Assert.AreEqual("XBTUSD", representation.Bids.CurrencyPair);
            // Check the Currency Pair for Ask Book
            Assert.AreEqual("XBTUSD", representation.Asks.CurrencyPair);

            // Count of the number of Bids in the Bid Order Book
            Assert.AreEqual(3, representation.Bids.Count());
            // Count of the number of Asks in the Ask Order Book
            Assert.AreEqual(3, representation.Asks.Count());

            Assert.AreEqual(50, representation.Bids.ToList()[0].Volume);     // Highest Bid Volumein Bid Order Book
            Assert.AreEqual(483.34M, representation.Bids.ToList()[0].Price); // Highest Bid Price in Bid Order Book

            Assert.AreEqual(150, representation.Asks.ToList()[0].Volume);    // Highest Ask Volumein Ask Order Book
            Assert.AreEqual(491.34M, representation.Asks.ToList()[0].Price); // Highest Ask Price in Ask Order Book
        }
Exemple #5
0
        public void PutLeaseUpdatesLease()
        {
            int     leaseIdForTest   = 1;
            decimal leaseRentForTest = 987654321;

            Constants.RentPeriod leaseTypeForTest = Constants.RentPeriod.Daily;

            //Arrange: Instantiate LeasesController so its methods can be called
            var leaseController = new LeasesController();

            //Act:
            // Get an existing lease, change it, and
            //  pass it to PutLease

            IHttpActionResult result = leaseController.GetLease(leaseIdForTest);
            OkNegotiatedContentResult <LeaseModel> contentResult =
                (OkNegotiatedContentResult <LeaseModel>)result;
            LeaseModel updatedLease = (LeaseModel)contentResult.Content;

            decimal leaseRentBeforeUpdate = updatedLease.Rent;

            Constants.RentPeriod leaseTypeBeforeUpdate = updatedLease.LeaseType;

            updatedLease.Rent      = leaseRentForTest;
            updatedLease.LeaseType = leaseTypeForTest;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the lease and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = leaseController.GetLease(leaseIdForTest);

            Assert.IsInstanceOfType(result,
                                    typeof(OkNegotiatedContentResult <LeaseModel>));

            OkNegotiatedContentResult <LeaseModel> readContentResult =
                (OkNegotiatedContentResult <LeaseModel>)result;

            updatedLease = (LeaseModel)readContentResult.Content;

            Assert.IsTrue(updatedLease.Rent == leaseRentForTest);
            Assert.IsTrue(updatedLease.LeaseType == leaseTypeForTest);

            updatedLease.Rent      = leaseRentBeforeUpdate;
            updatedLease.LeaseType = leaseTypeBeforeUpdate;

            result = leaseController.PutLease
                         (updatedLease.LeaseId, updatedLease);
        }
        public void BeAbleToReturnEarningsInACertainTimePeriod()
        {
            string from = "2007-09-17T22:02:51Z";
            string to   = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");

            IHttpActionResult actionResult = EARNINGS_CONTROLLER.GetAllEarnings(from, to);
            OkNegotiatedContentResult <double> contentResult = (OkNegotiatedContentResult <double>)actionResult;

            Assert.IsTrue(contentResult.Content > 0);
        }
Exemple #7
0
        public static OkNegotiatedContentResult <T> OkWithHeader <T>(this ApiController baseClass, T Item, IDictionary <string, string> headers) where T : class
        {
            var result = new OkNegotiatedContentResult <T>(Item, baseClass);

            foreach (var item in headers)
            {
                result.Request.Headers.Add(item.Key, item.Value);
            }
            return(result);
        }
 private static void ShouldReturnOrganization(OkNegotiatedContentResult <Models.Api.Organization> result)
 {
     result.Should().NotBeNull();
     result.Content.Should().NotBeNull();
     result.Content.Name.Should().Be(OrganizationName);
     result.Content.Number.Should().Be(OrganizationNumber);
     result.Content.ShortName.Should().Be(OrganizationShortName);
     //result.Content.LogoUrl.Should().Be(LocationUrl + Organization.DataDirectory + OrganizationLogoFilename);
     //result.Content.LogoLargeUrl.Should().Be(LocationUrl + Organization.DataDirectory + OrganizationLogoLargeFilename);
 }
Exemple #9
0
        public void Public_Controller_Get_ShouldOk()
        {
            // Action
            IHttpActionResult callback = _publicController.IsAlive();

            //Assert
            OkNegotiatedContentResult <bool> httpResponse = callback.Should().BeOfType <OkNegotiatedContentResult <bool> >().Subject;

            httpResponse.Content.Should().BeTrue();
        }
 public void InsertNullMemberRatingTest()
 {
     OkNegotiatedContentResult <decimal?> pk = (OkNegotiatedContentResult <decimal?>)_controller.Insert(new MembersModel()
     {
         Name       = "Mr Joe Bloe [TEST]",
         DOB        = new DateTime(2000, 1, 1),
         SumInsured = 121000M,
         Occupation = null
     });
 }
        public void LogoutFailTest_ChecksThatExceptionIsThrownWhenInvalidActivationKeyIsGiven_VerifiesAndAssertsTheReturnedValueAndQueriesDatabase()
        {
            // Register User
            RegistrationController registrationController = (RegistrationController)_applicationContext["RegistrationController"];
            IHttpActionResult      httpActionResult       = registrationController.Register(new SignUpParam("*****@*****.**", "user", "123", "Pakistan",
                                                                                                            TimeZone.CurrentTimeZone, ""));
            OkNegotiatedContentResult <string> okResponseMessage =
                (OkNegotiatedContentResult <string>)httpActionResult;
            string activationKey = okResponseMessage.Content;

            Assert.IsNotNullOrEmpty(activationKey);

            // Activate Account
            UserController userController = (UserController)_applicationContext["UserController"];

            httpActionResult = userController.ActivateUser(new UserActivationParam("user", "123", activationKey));
            OkNegotiatedContentResult <string> okResponseMessage1 =
                (OkNegotiatedContentResult <string>)httpActionResult;

            Assert.AreEqual(okResponseMessage1.Content, "activated");

            // Login
            LoginController loginController = (LoginController)_applicationContext["LoginController"];

            httpActionResult = loginController.Login(new LoginParams("user", "123"));
            OkNegotiatedContentResult <UserValidationEssentials> keys =
                (OkNegotiatedContentResult <UserValidationEssentials>)httpActionResult;

            Assert.IsNotNullOrEmpty(keys.Content.ApiKey);
            Assert.IsNotNullOrEmpty(keys.Content.SecretKey);
            Assert.IsNotNullOrEmpty(keys.Content.SessionLogoutTime.ToString());

            // Verify that Security Keys are in the database
            ISecurityKeysRepository securityKeysRepository = (ISecurityKeysRepository)_applicationContext["SecurityKeysPairRepository"];
            SecurityKeysPair        securityKeysPair       = securityKeysRepository.GetByApiKey(keys.Content.ApiKey);

            Assert.IsNotNull(securityKeysPair);
            Assert.AreEqual(keys.Content.SecretKey, securityKeysPair.SecretKey);
            Assert.IsTrue(securityKeysPair.SystemGenerated);

            LogoutController logoutController = (LogoutController)_applicationContext["LogoutController"];

            logoutController.Request = new HttpRequestMessage(HttpMethod.Get, "");
            logoutController.Request.Headers.Add("Auth", "123");
            IHttpActionResult            logoutResult     = logoutController.Logout();
            BadRequestErrorMessageResult logoutOkResponse = (BadRequestErrorMessageResult)logoutResult;

            Assert.IsNotNull(logoutOkResponse);

            // Verify that the Security Keys are not in the database
            securityKeysPair = securityKeysRepository.GetByApiKey(keys.Content.ApiKey);
            Assert.IsNotNull(securityKeysPair);
            Assert.AreEqual(keys.Content.SecretKey, securityKeysPair.SecretKey);
            Assert.IsTrue(securityKeysPair.SystemGenerated);
        }
        public void PutTenantUpdatesTenant()
        {
            int    tenantIdForTest        = 1;
            string tenantFirstNameForTest = "Testy";
            string tenantLastNameForTest  = "Testerson";

            //Arrange: Instantiate TenantsController so its methods can be called
            var tenantController = new TenantsController();

            //Act:
            // Get an existing tenant, change it, and
            //  pass it to PutTenant

            IHttpActionResult result = tenantController.GetTenant(tenantIdForTest);
            OkNegotiatedContentResult <TenantModel> contentResult =
                (OkNegotiatedContentResult <TenantModel>)result;
            TenantModel updatedTenant = (TenantModel)contentResult.Content;

            string tenantFirstNameBeforeUpdate = updatedTenant.FirstName;
            string tenantLastNameBeforeUpdate  = updatedTenant.LastName;

            updatedTenant.FirstName = tenantFirstNameForTest;
            updatedTenant.LastName  = tenantLastNameForTest;

            result = tenantController.PutTenant
                         (updatedTenant.TenantId, updatedTenant);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the tenant and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = tenantController.GetTenant(tenantIdForTest);

            Assert.IsInstanceOfType(result,
                                    typeof(OkNegotiatedContentResult <TenantModel>));

            OkNegotiatedContentResult <TenantModel> readContentResult =
                (OkNegotiatedContentResult <TenantModel>)result;

            updatedTenant = (TenantModel)readContentResult.Content;

            Assert.IsTrue(updatedTenant.FirstName == tenantFirstNameForTest);
            Assert.IsTrue(updatedTenant.LastName == tenantLastNameForTest);

            updatedTenant.FirstName = tenantFirstNameBeforeUpdate;
            updatedTenant.LastName  = tenantLastNameBeforeUpdate;

            result = tenantController.PutTenant
                         (updatedTenant.TenantId, updatedTenant);
        }
Exemple #13
0
        private OkNegotiatedContentResult <T> OkWithHeader <T>(T Item, IDictionary <string, string> headers) where T : class
        {
            var result = new OkNegotiatedContentResult <T>(Item, this);

            foreach (var item in headers)
            {
                result.Request.Headers.Remove(item.Key);
                result.Request.Headers.Add(item.Key, item.Value);
            }
            return(result);
        }
        public void VerifyTierLevelTest_TestsIfTheTierLevelIsVerifiedAsExpected_QueriesDatabaseToConfirm()
        {
            UserValidationEssentials essentials     = AccessControlUtility.RegisterAndLogin("user", "*****@*****.**", "123", _applicationContext);
            TierController           tierController = _applicationContext["TierController"] as TierController;

            Assert.IsNotNull(tierController);

            tierController.Request = new HttpRequestMessage(HttpMethod.Post, "");
            tierController.Request.Headers.Add("Auth", essentials.ApiKey);

            tierController.GetVerifyForTier1(new Tier1Param("User", DateTime.Now.AddDays(-10).ToShortDateString(), "656667"));
            // Tier 2 will not be considered for verification because Tier 1 is not yet verified
            tierController.GetVerifyForTier2(new Tier2Param("asd", "", "", "punjab", "Isb", "123"));

            IHttpActionResult httpActionResult = tierController.GetTierStatuses();
            OkNegotiatedContentResult <UserTierStatusRepresentation[]> statuses = (OkNegotiatedContentResult <UserTierStatusRepresentation[]>)httpActionResult;

            Assert.AreEqual(statuses.Content.Length, 5);
            Assert.AreEqual(statuses.Content[0].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[1].Status, Status.Preverified.ToString());
            Assert.AreEqual(statuses.Content[2].Status, Status.NonVerified.ToString());

            IHttpActionResult verifyTierLevelResult = tierController.VerifyTierLevel(new VerifyTierLevelParams("Tier 1", essentials.ApiKey));
            OkNegotiatedContentResult <VerifyTierLevelResponse> verificationResponse = (OkNegotiatedContentResult <VerifyTierLevelResponse>)verifyTierLevelResult;

            Assert.IsTrue(verificationResponse.Content.VerificationSuccessful);

            httpActionResult = tierController.GetTierStatuses();
            statuses         = (OkNegotiatedContentResult <UserTierStatusRepresentation[]>)httpActionResult;
            Assert.AreEqual(statuses.Content.Length, 5);
            Assert.AreEqual(statuses.Content[0].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[1].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[2].Status, Status.NonVerified.ToString());

            // Tier 2 will now be verified as Tier 1 is already verified
            tierController.GetVerifyForTier2(new Tier2Param("asd", "", "", "punjab", "Isb", "123"));
            httpActionResult = tierController.GetTierStatuses();
            statuses         = (OkNegotiatedContentResult <UserTierStatusRepresentation[]>)httpActionResult;
            Assert.AreEqual(statuses.Content.Length, 5);
            Assert.AreEqual(statuses.Content[0].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[1].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[2].Status, Status.Preverified.ToString());

            verifyTierLevelResult = tierController.VerifyTierLevel(new VerifyTierLevelParams("Tier 2", essentials.ApiKey));
            verificationResponse  = (OkNegotiatedContentResult <VerifyTierLevelResponse>)verifyTierLevelResult;
            Assert.IsTrue(verificationResponse.Content.VerificationSuccessful);

            httpActionResult = tierController.GetTierStatuses();
            statuses         = (OkNegotiatedContentResult <UserTierStatusRepresentation[]>)httpActionResult;
            Assert.AreEqual(statuses.Content.Length, 5);
            Assert.AreEqual(statuses.Content[0].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[1].Status, Status.Verified.ToString());
            Assert.AreEqual(statuses.Content[2].Status, Status.Verified.ToString());
        }
Exemple #15
0
        public void Pomasters_DeletePomaster_ShouldReturnOK()
        {
            //Arrange
            //Initialize();

            //Act
            OkNegotiatedContentResult <POMASTER> result = pomasterController.DeletePOMASTER("1") as OkNegotiatedContentResult <POMASTER>;

            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.Content.PONO);
        }
Exemple #16
0
        public void Podetails_DeletePodetail_ShouldReturnOK()
        {
            //Arrange
            //Initialize();

            //Act
            OkNegotiatedContentResult <PODETAIL> result = podetailController.DeletePODETAIL("1", "1") as OkNegotiatedContentResult <PODETAIL>;

            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.Content.PONO);
        }
Exemple #17
0
        public void PutPropertyUpdatesProperty()
        {
            int    propertyIdForTest   = 1;
            string propertyNameForTest = "Lofts";
            string address1ForTest     = "234 Smith Street";

            //Arrange: Instantiate PropertiesController so its methods can be called
            var propertyController = new PropertiesController();

            //Act:
            // Get an existing property, change it, and
            //  pass it to PutProperty

            IHttpActionResult result = propertyController.GetProperty(propertyIdForTest);
            OkNegotiatedContentResult <PropertyModel> contentResult =
                (OkNegotiatedContentResult <PropertyModel>)result;
            PropertyModel updatedProperty = (PropertyModel)contentResult.Content;

            string propertyNameBeforeUpdate     = updatedProperty.Name;
            string propertyAddress1BeforeUpdate = updatedProperty.Address1;

            updatedProperty.Name     = propertyNameForTest;
            updatedProperty.Address1 = address1ForTest;

            result = propertyController.PutProperty
                         (updatedProperty.PropertyId, updatedProperty);

            //Assert:
            // Verify that HTTP status code is OK
            // Get the property and verify that it was updated

            var statusCode = (StatusCodeResult)result;

            Assert.IsTrue(statusCode.StatusCode == System.Net.HttpStatusCode.NoContent);

            result = propertyController.GetProperty(propertyIdForTest);

            Assert.IsInstanceOfType(result,
                                    typeof(OkNegotiatedContentResult <PropertyModel>));

            OkNegotiatedContentResult <PropertyModel> readContentResult =
                (OkNegotiatedContentResult <PropertyModel>)result;

            updatedProperty = (PropertyModel)readContentResult.Content;

            Assert.IsTrue(updatedProperty.Name == propertyNameForTest);
            Assert.IsTrue(updatedProperty.Address1 == address1ForTest);

            updatedProperty.Name     = propertyNameBeforeUpdate;
            updatedProperty.Address1 = propertyAddress1BeforeUpdate;

            result = propertyController.PutProperty
                         (updatedProperty.PropertyId, updatedProperty);
        }
        public void UserJobsApiController_GetOne()
        {
            //Arrange
            UserJobsApiController controller = new UserJobsApiController(new FakeUserJobsApiRepository());
            //Act
            OkNegotiatedContentResult <UserJob> result = controller.GetUserJob(1) as OkNegotiatedContentResult <UserJob>;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
        }
Exemple #19
0
        public void Suppliers_DeleteSupplier_ShouldReturnOK()
        {
            //Arrange
            //Initialize();

            //Act
            OkNegotiatedContentResult <SUPPLIER> result = supplierController.DeleteSUPPLIER("1") as OkNegotiatedContentResult <SUPPLIER>;

            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.Content.SUPLNO);
        }
 public void InsertNullNameTest()
 {
     OkNegotiatedContentResult <decimal?> pk = (OkNegotiatedContentResult <decimal?>)_controller.Insert(new OccupationsModel()
     {
         Name             = null,
         OccupationRating = new OccupationRatingsModel()
         {
             Id = 1 // Professional; 1.0
         }
     });
 }
        public void RegisterAccountTest_IfRegisterControllerIsCalled_SignUpShouldBeDoneSuccessfullyAndActivationKeyShouldBeReceived()
        {
            RegistrationController registrationController = (RegistrationController)_applicationContext["RegistrationController"];
            IHttpActionResult      httpActionResult       = registrationController.Register(new SignUpParam("*****@*****.**", "user", "123", "Pakistan",
                                                                                                            TimeZone.CurrentTimeZone, ""));
            OkNegotiatedContentResult <string> okResponseMessage =
                (OkNegotiatedContentResult <string>)httpActionResult;
            string activationKey = okResponseMessage.Content;

            Assert.IsNotNullOrEmpty(activationKey);
        }
Exemple #22
0
        public void Items_DeleteItem_ShouldReturnOK()
        {
            //Arrange
            //Initialize();

            //Act
            OkNegotiatedContentResult <ITEM> result = itemController.DeleteITEM("1") as OkNegotiatedContentResult <ITEM>;

            Assert.IsNotNull(result);
            Assert.AreEqual("1", result.Content.ITCODE);
        }
        public void ProposalApiController_GetOne()
        {
            //Arrange
            ProposalsApiController controller = new ProposalsApiController(new FakeProposalsApiRepository());
            //Act
            OkNegotiatedContentResult <Proposal> result = controller.GetProposal(1) as OkNegotiatedContentResult <Proposal>;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
        }
Exemple #24
0
        public void GetChannelByName()
        {
            this.sessionContext.Channels = this.GetFakeChannels();
            this.sessionContext.Channels.ToList().Add(new Channel {
                ChannelName = "test channel 3"
            });
            OkNegotiatedContentResult <IEnumerable <Channel> > channels = this.channelController.GetChannel("test channel 2") as OkNegotiatedContentResult <IEnumerable <Channel> >;

            Assert.AreEqual(1, channels.Content.Count(), "only one channel should be returned by the query");
            Assert.AreEqual("test channel 2", channels.Content.FirstOrDefault().ChannelName, "the channels were not returned properly");
        }
Exemple #25
0
        public void GetAll_Should_return_correct_statusCode_and_a_list_of_users()
        {
            var expectedResult = new OkNegotiatedContentResult <List <User> >(USERS, new UsersController());

            _mockAutheniication.Setup(f => f.IsAuthentificated(It.IsAny <IPrincipal>())).Returns(true);
            _mockUserManager.Setup(f => f.GetAll()).Returns(USERS);


            var result = _usersController.Get();

            Assert.AreEqual(((OkNegotiatedContentResult <List <User> >)result).Content, expectedResult.Content);
        }
        public void TechnicianApiController_GetOne()
        {
            //Arrange
            TechniciansApiController controller = new TechniciansApiController(new FakeTechnicianApiRepository());

            //Act
            OkNegotiatedContentResult <Technician> result = controller.GetTechnician(1) as OkNegotiatedContentResult <Technician>;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
        }
Exemple #27
0
        private void ValidateCuisineCollectionResponse(OkNegotiatedContentResult <IEnumerable <API.ViewModels.Cuisine> > contentResult, List <API.ViewModels.Cuisine> expectedResponse, int expectedCount)
        {
            var cuisineCountIndex = 0;

            foreach (var actualCuisine in contentResult.Content)
            {
                var expectedCuisine = expectedResponse[cuisineCountIndex];
                ValidateCuisineResponse(expectedCuisine, actualCuisine);
                cuisineCountIndex++;
            }
            Assert.AreEqual(expectedCount, cuisineCountIndex);
        }
        public void EvaluateRequestedDateTime_WithValidDateTime_BadRequestIsNull_ReturnsTrue()
        {
            IHttpActionResult badRequest    = new OkNegotiatedContentResult <object>(new object(), _controller);
            DateTime          parsed        = DateTime.MinValue;
            string            validArgument = _lifetimeStub.Since.AddMinutes(1).ToIso8061BasicString();

            bool success = _controller.EvaluateRequestedDateTime(validArgument, out parsed, out badRequest);

            Assert.IsTrue(success);
            Assert.IsNull(badRequest);
            Assert.AreEqual(_lifetimeStub.Since.AddMinutes(1), parsed);
        }
        public void BeAbleToReturnEarningsPerProviderInACertainTimePeriod()
        {
            string from = "2003-09-17T22:02:51Z";
            string to   = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ");

            IHttpActionResult actionResult = EARNINGS_CONTROLLER.GetEarningsPerProvider(from, to);
            OkNegotiatedContentResult <IDictionary <Provider, double> > contentResult =
                (OkNegotiatedContentResult <IDictionary <Provider, double> >)actionResult;

            Assert.IsTrue(contentResult.Content[FIRST_TEST_PROVIDER] > 0);
            Assert.IsTrue(contentResult.Content[SECOND_TEST_PROVIDER] > 0);
        }
        public async Task CatalogWebApiGetId()
        {
            // Arrange
            CatalogController controller = new CatalogController(catalogService.Object);

            // Act
            OkNegotiatedContentResult <Product> result = await controller.Get("15") as OkNegotiatedContentResult <Product>;

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("15", result.Content.Name);
        }
        public void Post_ValidObjectPassed_HospitalCreationFail()
        {
            // Arrange
            Hospital hospital = new Hospital();

            // Act
            IHttpActionResult actionResult = hospitalController.Post(hospital);
            OkNegotiatedContentResult <string> conNegResult = Assert.IsType <OkNegotiatedContentResult <string> >(actionResult);

            // Assert
            Assert.Equal("data:False", conNegResult.Content);
        }
        public async Task OkNegotiatedContentResult_SetsStatusCode()
        {
            // Arrange
            var httpContext = new DefaultHttpContext();
            httpContext.RequestServices = CreateServices();

            var stream = new MemoryStream();
            httpContext.Response.Body = stream;

            var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
            var result = new OkNegotiatedContentResult<Product>(new Product());

            // Act
            await result.ExecuteResultAsync(context);

            // Assert
            Assert.Equal(StatusCodes.Status200OK, context.HttpContext.Response.StatusCode);
        }
        public void GetEmployees_EmployeeListFromBusinessLayer_OkReturnedWithEmployeeList()
        {
            // ARRANGE
            // Mock the business Layer
            mockHumanResourcesService.Setup(x => x.GetEmployees()).Returns(new List<BusinessObjects.Employee> { ceoBo });
            e = new Controllers.EmployeeController(mockHumanResourcesService.Object);

            // Create expected result
            var expectedResult =
                new OkNegotiatedContentResult<List<EmployeeModel>>(new List<EmployeeModel> { ceoModel }, e);


            // ACT
            // Call the API method, casting to expected result type
            var returns = (OkNegotiatedContentResult<List<EmployeeModel>>)e.GetEmployees();

            // ASSERT
            // Explicitly state that we want this type
            Assert.IsInstanceOf<OkNegotiatedContentResult<List<EmployeeModel>>>(returns);
            // Make sure there's 1 item in the list (mocked service returns 1 item)
            Assert.AreEqual(returns.Content.Count(), 1);
            // Make sure that item contains the expected employee data
            Assert.True(returns.Content.FirstOrDefault().Equals(ceoModel));
        }
        public void EvaluateRequestedDateTime_WithValidDateTime_BadRequestIsNull_ReturnsTrue()
        {
            IHttpActionResult badRequest = new OkNegotiatedContentResult<object>(new object(), _controller);
            DateTime parsed = DateTime.MinValue;
            string validArgument = _lifetimeStub.Since.AddMinutes(1).ToIso8061BasicString();

            bool success = _controller.EvaluateRequestedDateTime(validArgument, out parsed, out badRequest);

            Assert.IsTrue(success);
            Assert.IsNull(badRequest);
            Assert.AreEqual(_lifetimeStub.Since.AddMinutes(1), parsed);
        }
Exemple #35
0
 public GivenTheFilenameIsValid()
 {
     fakeFile = "aFakeFile.txt";
     fakeUser = "******";
     _fakeLockingService = new FakeLockingService();
     lockingController = new LockingController(_fakeLockingService);
     result = lockingController.Lock(fakeUser, fakeFile);
     content = Assert.IsType<OkNegotiatedContentResult<string>>(result);
 }