Ejemplo n.º 1
0
        public void WhenPosting()
        {
            _errorInfo = new ErrorInformation
            {
                ErrorId = "errorId",
                Error = "SomeError",
                InfoUrl = "http://error",
                SourceId = "srcId"
            };

            _urls = new List<string>
            {
                "url1",
                "url2"
            };

            _configuration = new Mock<IProxyConfiguration>();
            _configuration
                .SetupGet(c => c.AppMonitorUrls)
                .Returns(_urls);

            _errorPoster = new Mock<IErrorPoster>();

            var controller = new ErrorController(_configuration.Object, _errorPoster.Object);
            _result = controller.Post(_errorInfo);
        }
 public ActionResultDelegate(
     IHttpActionResult next,
     Func<CancellationToken,IHttpActionResult,Task<HttpResponseMessage>> func)
 {
     _next = next;
     _func = func;
 }
Ejemplo n.º 3
0
            public static void AssertModelAreEqual(IHttpActionResult response, Type type)
            {
                var result = GetResponseMessage(response);

                var content = (ObjectContent)result.Content;

                Assert.IsNotNull(content);
                Assert.IsInstanceOfType(content.Value, type);
            }
Ejemplo n.º 4
0
            public static void AssertHeaderLocationEndsWith(IHttpActionResult response, string expectedLocation)
            {
                var result = GetResponseMessage(response);

                var actualLocation = result.Headers.SingleOrDefault(x => x.Key == "Location");

                Assert.IsNotNull(actualLocation);
                Assert.IsTrue(actualLocation.Value.First().EndsWith(expectedLocation));
            }
        public FailedAuthenticationResult(IHttpActionResult errorResult)
        {
            if (errorResult == null)
            {
                throw new ArgumentNullException("errorResult");
            }

            _errorResult = errorResult;
        }
        public void Given_A_ClientId_HAS_Installation_Receipts_When_Service_Called_Return_Installation_Receipts()
        {
            _actionResult = _controller.GetAllInstallationReceipts("2");
            Assert.IsInstanceOf<OkNegotiatedContentResult<List<InstallationReceipt>>>(_actionResult);

            var contentResult = _actionResult as OkNegotiatedContentResult<List<InstallationReceipt>>;
            Assert.IsNotNull(contentResult);
            Assert.IsTrue(contentResult.Content.Count > 1);
            Assert.AreEqual(InstallationReceipts.Count, contentResult.Content.Count);
        }
        public ExceptionFilterResult(HttpActionContext context, IExceptionFilter[] filters,
            IHttpActionResult innerResult)
        {
            Contract.Assert(context != null);
            Contract.Assert(filters != null);
            Contract.Assert(innerResult != null);

            _context = context;
            _filters = filters;
            _innerResult = innerResult;
        }
Ejemplo n.º 8
0
        private bool CheckModelState(out IHttpActionResult updateMessage)
        {
            if (ModelState.IsValid)
            {
                updateMessage = null;
                return false;
            }

            updateMessage = this.BadRequest(ModelState);
            return true;
        }
Ejemplo n.º 9
0
            public static HttpResponseMessage AssertHttpStatusCode(IHttpActionResult response, HttpStatusCode statusCode)
            {
                Assert.IsNotNull(response);

                var result = GetResponseMessage(response);

                Assert.IsInstanceOfType(result, typeof(HttpResponseMessage));
                Assert.AreEqual(statusCode, result.StatusCode);

                return result;
            }
        public AuthenticationFilterResult(HttpActionContext context, ApiController controller,
            IAuthenticationFilter[] filters, IHttpActionResult innerResult)
        {
            Contract.Assert(context != null);
            Contract.Assert(controller != null);
            Contract.Assert(filters != null);
            Contract.Assert(innerResult != null);

            _context = context;
            _controller = controller;
            _filters = filters;
            _innerResult = innerResult;
        }
        public AuthenticationFilterResult(HttpActionContext context, IAuthenticationFilter[] filters,
            IHostPrincipalService principalService, HttpRequestMessage request, IHttpActionResult innerResult)
        {
            Contract.Assert(context != null);
            Contract.Assert(filters != null);
            Contract.Assert(principalService != null);
            Contract.Assert(innerResult != null);

            _context = context;
            _filters = filters;
            _principalService = principalService;
            _request = request;
            _innerResult = innerResult;
        }
        private bool ValidateTakeParameter(int take, out IHttpActionResult httpActionResult)
        {
            if (take <= ServicesConstants.MaximumTakeValueForPaging)
            {
                httpActionResult = null;
                return false;
            }

            httpActionResult =
                this.BadRequest(string.Format("Take cannot be more than {0}",
                    ServicesConstants.MaximumTakeValueForPaging));

            return true;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HttpAuthenticationChallengeContext"/> class.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        /// <param name="result">The current action result.</param>
        public HttpAuthenticationChallengeContext(HttpActionContext actionContext, IHttpActionResult result)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException("actionContext");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            ActionContext = actionContext;
            Result = result;
        }
Ejemplo n.º 14
0
            public static void AssertBadRequest(IHttpActionResult response)
            {
                var result = AssertHttpStatusCode(response, HttpStatusCode.BadRequest);
                var errors = GetModelState(result);

                Assert.IsTrue(errors.Values.Count > 0);

                var fakeErrorExists = false;

                foreach (string[] error in errors.Values)
                {
                    foreach (var innerError in error.Where(innerError => innerError.Equals("Fake Error")))
                    {
                        fakeErrorExists = true;
                    }
                }

                Assert.IsTrue(fakeErrorExists);
            }
        /// <inheritdoc />
        public Task<IHttpActionResult> ChallengeAsync(HttpActionContext context, IHttpActionResult innerResult,
            CancellationToken cancellationToken)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            HttpRequestMessage request = context.Request;

            if (request == null)
            {
                throw new InvalidOperationException(OwinResources.HttpAuthenticationContext_RequestMustNotBeNull);
            }

            OwinResponse response = request.GetOwinResponse();

            // Control the challenges that OWIN middleware adds later.
            response.AuthenticationResponseChallenge = AddChallengeAuthenticationType(
                response.AuthenticationResponseChallenge, _authenticationType);

            // Otherwise, return the provided result as-is.
            return Task.FromResult(innerResult);
        }
 public WrappedHttpActionResult(IHttpActionResult inner, Action<HttpResponseMessage> responseAction)
     : this(inner, null, responseAction)
 {
 }
 private static AuthenticationFilterResult CreateProductUnderTest(HttpActionContext context,
     IAuthenticationFilter[] filters, IHostPrincipalService principalService, HttpRequestMessage request,
     IHttpActionResult innerResult)
 {
     return new AuthenticationFilterResult(context, filters, principalService, request, innerResult);
 }
Ejemplo n.º 18
0
 public static T GetValue <T>(this IHttpActionResult result, string parameterName)
 {
     return(MobSocialTestCase.GetValueFromJsonResult <T>(result, parameterName));
 }
 public ResultWithChallenge(IHttpActionResult next)
 {
     this.next = next;
 }
Ejemplo n.º 20
0
 public static void ShouldBe(this IHttpActionResult actionResult, HttpStatusCode statusCode)
 {
     actionResult.ExecuteAsync(CancellationToken.None).Result
     .StatusCode.Should().Be(statusCode);
 }
Ejemplo n.º 21
0
        public async Task TestUsersApiPutAsync()
        {
            // Find out how many users there are

            // Arrange
            int actualUserCount = 0;

            // Act
            IHttpActionResult userResult = controller.Get();
            var message = await userResult.ExecuteAsync(new System.Threading.CancellationToken());

            var users = await message.Content.ReadAsAsync <IEnumerable <User> >();

            foreach (var user in users)
            {
                actualUserCount++;
            }

            //////////////////////////////////////////////////////////////////

            // PUT a new user with invalid model - expect bad request message
            User newUser = new User();

            newUser.Username = "******";
            //newUser.Password = "******";
            newUser.Email = "*****@*****.**";
            newUser.Id    = new Guid("55555555-4444-4444-4444-222222222222");

            controller.ModelState.AddModelError("k1", "password is too short");
            IHttpActionResult result = controller.Put(new UserAPI(newUser));
            var badMessage           = await result.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.BadRequest, badMessage.StatusCode);

            // Make new user's model valid and PUT
            //newUser.Password = "******";
            controller.ModelState.Remove("k1");
            IHttpActionResult goodResult = controller.Put(new UserAPI(newUser));
            var goodMessage = await goodResult.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.OK, goodMessage.StatusCode);

            /////////////////////////////////////////////////////////////////

            // Expect user count to be one more than before

            // Arrange
            int expectedUserCount = actualUserCount + 1;

            // reset count to test again after the PUT
            actualUserCount = 0;

            // Act
            userResult = controller.Get();
            message    = await userResult.ExecuteAsync(new System.Threading.CancellationToken());

            users = await message.Content.ReadAsAsync <IEnumerable <User> >();

            foreach (var user in users)
            {
                actualUserCount++;
            }

            // Assert
            Assert.AreEqual(expectedUserCount, actualUserCount);

            /////////////////////////////////////////////////////////////////

            // Now do an update to existing user with PUT
            // user count shouldn't change

            // Arrange
            expectedUserCount = actualUserCount;
            // reset count to test again after the PUT
            actualUserCount = 0;

            User oldUser = new User();

            oldUser.Username = "******";
            //oldUser.Password = "******";
            oldUser.Email = "*****@*****.**";
            oldUser.Id    = new Guid("55555555-4444-4444-4444-222222222222");

            goodResult  = controller.Put(new UserAPI(oldUser));
            goodMessage = await goodResult.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.OK, goodMessage.StatusCode);

            // Act
            userResult = controller.Get();
            message    = await userResult.ExecuteAsync(new System.Threading.CancellationToken());

            users = await message.Content.ReadAsAsync <IEnumerable <User> >();

            foreach (var user in users)
            {
                actualUserCount++;
            }

            // Assert
            Assert.AreEqual(expectedUserCount, actualUserCount);
        }
Ejemplo n.º 22
0
 public static IHttpActionResult WithError(this IHttpActionResult inner, string errorMessage)
 {
     return(new HttpActionResultWithError(inner, errorMessage));
 }
Ejemplo n.º 23
0
        public void FailWithNotFoundIfToBeDeletedClientDoesntExistInRepository()
        {
            IHttpActionResult actionResult = CONTROLLER.DeleteClient(0);

            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
Ejemplo n.º 24
0
        public void SamplingPlanEmail_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanEmailController samplingPlanEmailController = new SamplingPlanEmailController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanEmailController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanEmailController.DatabaseType);

                    SamplingPlanEmail samplingPlanEmailLast = new SamplingPlanEmail();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        SamplingPlanEmailService samplingPlanEmailService = new SamplingPlanEmailService(query, db, ContactID);
                        samplingPlanEmailLast = (from c in db.SamplingPlanEmails select c).FirstOrDefault();
                    }

                    // ok with SamplingPlanEmail info
                    IHttpActionResult jsonRet = samplingPlanEmailController.GetSamplingPlanEmailWithID(samplingPlanEmailLast.SamplingPlanEmailID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <SamplingPlanEmail> Ret = jsonRet as OkNegotiatedContentResult <SamplingPlanEmail>;
                    SamplingPlanEmail samplingPlanEmailRet            = Ret.Content;
                    Assert.AreEqual(samplingPlanEmailLast.SamplingPlanEmailID, samplingPlanEmailRet.SamplingPlanEmailID);

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

                    // Post to return newly added SamplingPlanEmail
                    samplingPlanEmailRet.SamplingPlanEmailID       = 0;
                    samplingPlanEmailController.Request            = new System.Net.Http.HttpRequestMessage();
                    samplingPlanEmailController.Request.RequestUri = new System.Uri("http://localhost:5000/api/samplingPlanEmail");
                    IHttpActionResult jsonRet3 = samplingPlanEmailController.Post(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet3 = jsonRet3 as CreatedNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNotNull(samplingPlanEmailRet3);
                    SamplingPlanEmail samplingPlanEmail = samplingPlanEmailRet3.Content;

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    // Delete to return success
                    IHttpActionResult jsonRet2 = samplingPlanEmailController.Delete(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet2 = jsonRet2 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNotNull(samplingPlanEmailRet2);

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

                    // Delete to return CSSPError because SamplingPlanEmailID of 0 does not exist
                    samplingPlanEmailRet.SamplingPlanEmailID = 0;
                    IHttpActionResult jsonRet4 = samplingPlanEmailController.Delete(samplingPlanEmailRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <SamplingPlanEmail> samplingPlanEmailRet4 = jsonRet4 as OkNegotiatedContentResult <SamplingPlanEmail>;
                    Assert.IsNull(samplingPlanEmailRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest4);
                }
            }
        }
Ejemplo n.º 25
0
 public static IHttpActionResult With(this IHttpActionResult inner, Action <HttpResponseMessage> responseAction)
 {
     return(new HttpActionResultWithAction(inner, responseAction));
 }
        public void InfrastructureLanguage_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    InfrastructureLanguageController infrastructureLanguageController = new InfrastructureLanguageController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(infrastructureLanguageController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, infrastructureLanguageController.DatabaseType);

                    InfrastructureLanguage infrastructureLanguageLast = new InfrastructureLanguage();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        InfrastructureLanguageService infrastructureLanguageService = new InfrastructureLanguageService(query, db, ContactID);
                        infrastructureLanguageLast = (from c in db.InfrastructureLanguages select c).FirstOrDefault();
                    }

                    // ok with InfrastructureLanguage info
                    IHttpActionResult jsonRet = infrastructureLanguageController.GetInfrastructureLanguageWithID(infrastructureLanguageLast.InfrastructureLanguageID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <InfrastructureLanguage> Ret = jsonRet as OkNegotiatedContentResult <InfrastructureLanguage>;
                    InfrastructureLanguage infrastructureLanguageRet       = Ret.Content;
                    Assert.AreEqual(infrastructureLanguageLast.InfrastructureLanguageID, infrastructureLanguageRet.InfrastructureLanguageID);

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

                    // Post to return newly added InfrastructureLanguage
                    infrastructureLanguageRet.InfrastructureLanguageID  = 0;
                    infrastructureLanguageController.Request            = new System.Net.Http.HttpRequestMessage();
                    infrastructureLanguageController.Request.RequestUri = new System.Uri("http://localhost:5000/api/infrastructureLanguage");
                    IHttpActionResult jsonRet3 = infrastructureLanguageController.Post(infrastructureLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <InfrastructureLanguage> infrastructureLanguageRet3 = jsonRet3 as CreatedNegotiatedContentResult <InfrastructureLanguage>;
                    Assert.IsNotNull(infrastructureLanguageRet3);
                    InfrastructureLanguage infrastructureLanguage = infrastructureLanguageRet3.Content;

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    // Delete to return success
                    IHttpActionResult jsonRet2 = infrastructureLanguageController.Delete(infrastructureLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <InfrastructureLanguage> infrastructureLanguageRet2 = jsonRet2 as OkNegotiatedContentResult <InfrastructureLanguage>;
                    Assert.IsNotNull(infrastructureLanguageRet2);

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

                    // Delete to return CSSPError because InfrastructureLanguageID of 0 does not exist
                    infrastructureLanguageRet.InfrastructureLanguageID = 0;
                    IHttpActionResult jsonRet4 = infrastructureLanguageController.Delete(infrastructureLanguageRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <InfrastructureLanguage> infrastructureLanguageRet4 = jsonRet4 as OkNegotiatedContentResult <InfrastructureLanguage>;
                    Assert.IsNull(infrastructureLanguageRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest4);
                }
            }
        }
 /// <summary>
 /// Add a custom header to an action result and return it.
 /// </summary>
 /// <param name="actionResult">Action result.</param>
 /// <param name="headerName">Name of the header.</param>
 /// <param name="headerValue">Value associated with the header.</param>
 /// <returns>Action result with a custom header.</returns>
 private IHttpActionResult CreateCustomActionResult(IHttpActionResult result, string headerName, string headerValue)
 {
     return(new CustomHeaderResult(result, headerName, new[] { headerValue }));
 }
Ejemplo n.º 28
0
        public void SamplingPlanSubsectorSite_Controller_GetSamplingPlanSubsectorSiteList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    SamplingPlanSubsectorSiteController samplingPlanSubsectorSiteController = new SamplingPlanSubsectorSiteController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(samplingPlanSubsectorSiteController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, samplingPlanSubsectorSiteController.DatabaseType);

                    SamplingPlanSubsectorSite samplingPlanSubsectorSiteFirst = new SamplingPlanSubsectorSite();
                    int   count = -1;
                    Query query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(query, db, ContactID);
                        samplingPlanSubsectorSiteFirst = (from c in db.SamplingPlanSubsectorSites select c).FirstOrDefault();
                        count = (from c in db.SamplingPlanSubsectorSites select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with SamplingPlanSubsectorSite info
                    IHttpActionResult jsonRet = samplingPlanSubsectorSiteController.GetSamplingPlanSubsectorSiteList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <SamplingPlanSubsectorSite> > ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlanSubsectorSite> >;
                    Assert.AreEqual(samplingPlanSubsectorSiteFirst.SamplingPlanSubsectorSiteID, ret.Content[0].SamplingPlanSubsectorSiteID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <SamplingPlanSubsectorSite> samplingPlanSubsectorSiteList = new List <SamplingPlanSubsectorSite>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        SamplingPlanSubsectorSiteService samplingPlanSubsectorSiteService = new SamplingPlanSubsectorSiteService(query, db, ContactID);
                        samplingPlanSubsectorSiteList = (from c in db.SamplingPlanSubsectorSites select c).OrderBy(c => c.SamplingPlanSubsectorSiteID).Skip(0).Take(2).ToList();
                        count = (from c in db.SamplingPlanSubsectorSites select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with SamplingPlanSubsectorSite info
                        jsonRet = samplingPlanSubsectorSiteController.GetSamplingPlanSubsectorSiteList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <SamplingPlanSubsectorSite> >;
                        Assert.AreEqual(samplingPlanSubsectorSiteList[0].SamplingPlanSubsectorSiteID, ret.Content[0].SamplingPlanSubsectorSiteID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with SamplingPlanSubsectorSite info
                            IHttpActionResult jsonRet2 = samplingPlanSubsectorSiteController.GetSamplingPlanSubsectorSiteList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <SamplingPlanSubsectorSite> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <SamplingPlanSubsectorSite> >;
                            Assert.AreEqual(samplingPlanSubsectorSiteList[1].SamplingPlanSubsectorSiteID, ret2.Content[0].SamplingPlanSubsectorSiteID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
 private ExceptionFilterResult CreateProductUnderTest(HttpActionContext context, IExceptionFilter[] filters,
     IHttpActionResult innerResult)
 {
     return new ExceptionFilterResult(context, filters, innerResult);
 }
Ejemplo n.º 30
0
        public void ResetPassword_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    ResetPasswordController resetPasswordController = new ResetPasswordController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(resetPasswordController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, resetPasswordController.DatabaseType);

                    ResetPassword resetPasswordLast = new ResetPassword();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        ResetPasswordService resetPasswordService = new ResetPasswordService(query, db, ContactID);
                        resetPasswordLast = (from c in db.ResetPasswords select c).FirstOrDefault();
                    }

                    // ok with ResetPassword info
                    IHttpActionResult jsonRet = resetPasswordController.GetResetPasswordWithID(resetPasswordLast.ResetPasswordID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <ResetPassword> Ret = jsonRet as OkNegotiatedContentResult <ResetPassword>;
                    ResetPassword resetPasswordRet = Ret.Content;
                    Assert.AreEqual(resetPasswordLast.ResetPasswordID, resetPasswordRet.ResetPasswordID);

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

                    // Post to return newly added ResetPassword
                    resetPasswordRet.ResetPasswordID           = 0;
                    resetPasswordController.Request            = new System.Net.Http.HttpRequestMessage();
                    resetPasswordController.Request.RequestUri = new System.Uri("http://localhost:5000/api/resetPassword");
                    IHttpActionResult jsonRet3 = resetPasswordController.Post(resetPasswordRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <ResetPassword> resetPasswordRet3 = jsonRet3 as CreatedNegotiatedContentResult <ResetPassword>;
                    Assert.IsNotNull(resetPasswordRet3);
                    ResetPassword resetPassword = resetPasswordRet3.Content;

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    // Delete to return success
                    IHttpActionResult jsonRet2 = resetPasswordController.Delete(resetPasswordRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <ResetPassword> resetPasswordRet2 = jsonRet2 as OkNegotiatedContentResult <ResetPassword>;
                    Assert.IsNotNull(resetPasswordRet2);

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

                    // Delete to return CSSPError because ResetPasswordID of 0 does not exist
                    resetPasswordRet.ResetPasswordID = 0;
                    IHttpActionResult jsonRet4 = resetPasswordController.Delete(resetPasswordRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <ResetPassword> resetPasswordRet4 = jsonRet4 as OkNegotiatedContentResult <ResetPassword>;
                    Assert.IsNull(resetPasswordRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest4);
                }
            }
        }
 private void WhenAnEmployeeIsCreated()
 {
     response = controller.Create(new Employee {
         Name = "Patrick Stewart", Email = "*****@*****.**"
     });
 }
Ejemplo n.º 32
0
        public void ResetPassword_Controller_GetResetPasswordList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    ResetPasswordController resetPasswordController = new ResetPasswordController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(resetPasswordController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, resetPasswordController.DatabaseType);

                    ResetPassword resetPasswordFirst = new ResetPassword();
                    int           count = -1;
                    Query         query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        ResetPasswordService resetPasswordService = new ResetPasswordService(query, db, ContactID);
                        resetPasswordFirst = (from c in db.ResetPasswords select c).FirstOrDefault();
                        count = (from c in db.ResetPasswords select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with ResetPassword info
                    IHttpActionResult jsonRet = resetPasswordController.GetResetPasswordList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <ResetPassword> > ret = jsonRet as OkNegotiatedContentResult <List <ResetPassword> >;
                    Assert.AreEqual(resetPasswordFirst.ResetPasswordID, ret.Content[0].ResetPasswordID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <ResetPassword> resetPasswordList = new List <ResetPassword>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        ResetPasswordService resetPasswordService = new ResetPasswordService(query, db, ContactID);
                        resetPasswordList = (from c in db.ResetPasswords select c).OrderBy(c => c.ResetPasswordID).Skip(0).Take(2).ToList();
                        count             = (from c in db.ResetPasswords select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with ResetPassword info
                        jsonRet = resetPasswordController.GetResetPasswordList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <ResetPassword> >;
                        Assert.AreEqual(resetPasswordList[0].ResetPasswordID, ret.Content[0].ResetPasswordID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with ResetPassword info
                            IHttpActionResult jsonRet2 = resetPasswordController.GetResetPasswordList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <ResetPassword> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <ResetPassword> >;
                            Assert.AreEqual(resetPasswordList[1].ResetPasswordID, ret2.Content[0].ResetPasswordID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Ejemplo n.º 33
0
        /// <inheritdoc/>
        public virtual async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
        {
            IHttpActionResult result = GetInnerActionResult();

            return(await result.ExecuteAsync(cancellationToken));
        }
        public void MWQMLookupMPN_Controller_Delete_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

                    MWQMLookupMPN mwqmLookupMPNLast = new MWQMLookupMPN();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNLast = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNWithID(mwqmLookupMPNLast.MWQMLookupMPNID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <MWQMLookupMPN> Ret = jsonRet as OkNegotiatedContentResult <MWQMLookupMPN>;
                    MWQMLookupMPN mwqmLookupMPNRet = Ret.Content;
                    Assert.AreEqual(mwqmLookupMPNLast.MWQMLookupMPNID, mwqmLookupMPNRet.MWQMLookupMPNID);

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

                    // Post to return newly added MWQMLookupMPN
                    mwqmLookupMPNRet.MWQMLookupMPNID           = 0;
                    mwqmLookupMPNRet.Tubes01                   = 1;
                    mwqmLookupMPNRet.Tubes1                    = 1;
                    mwqmLookupMPNRet.Tubes10                   = 1;
                    mwqmLookupMPNRet.MPN_100ml                 = 6;
                    mwqmLookupMPNController.Request            = new System.Net.Http.HttpRequestMessage();
                    mwqmLookupMPNController.Request.RequestUri = new System.Uri("http://localhost:5000/api/mwqmLookupMPN");
                    IHttpActionResult jsonRet3 = mwqmLookupMPNController.Post(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet3 = jsonRet3 as CreatedNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNotNull(mwqmLookupMPNRet3);
                    MWQMLookupMPN mwqmLookupMPN = mwqmLookupMPNRet3.Content;

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    // Delete to return success
                    IHttpActionResult jsonRet2 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet2 = jsonRet2 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNotNull(mwqmLookupMPNRet2);

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

                    // Delete to return CSSPError because MWQMLookupMPNID of 0 does not exist
                    mwqmLookupMPNRet.MWQMLookupMPNID = 0;
                    IHttpActionResult jsonRet4 = mwqmLookupMPNController.Delete(mwqmLookupMPNRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <MWQMLookupMPN> mwqmLookupMPNRet4 = jsonRet4 as OkNegotiatedContentResult <MWQMLookupMPN>;
                    Assert.IsNull(mwqmLookupMPNRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNotNull(badRequest4);
                }
            }
        }
 public AddChallengeOnUnauthorizedResult(AuthenticationHeaderValue challenge, IHttpActionResult innerResult)
 {
     Challenge   = challenge;
     InnerResult = innerResult;
 }
        public void MWQMLookupMPN_Controller_GetMWQMLookupMPNList_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    MWQMLookupMPNController mwqmLookupMPNController = new MWQMLookupMPNController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(mwqmLookupMPNController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, mwqmLookupMPNController.DatabaseType);

                    MWQMLookupMPN mwqmLookupMPNFirst = new MWQMLookupMPN();
                    int           count = -1;
                    Query         query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNFirst = (from c in db.MWQMLookupMPNs select c).FirstOrDefault();
                        count = (from c in db.MWQMLookupMPNs select c).Count();
                        count = (query.Take > count ? count : query.Take);
                    }

                    // ok with MWQMLookupMPN info
                    IHttpActionResult jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList();
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <List <MWQMLookupMPN> > ret = jsonRet as OkNegotiatedContentResult <List <MWQMLookupMPN> >;
                    Assert.AreEqual(mwqmLookupMPNFirst.MWQMLookupMPNID, ret.Content[0].MWQMLookupMPNID);
                    Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                    List <MWQMLookupMPN> mwqmLookupMPNList = new List <MWQMLookupMPN>();
                    count = -1;
                    query = new Query();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseTypeEnum.SqlServerTestDB))
                    {
                        MWQMLookupMPNService mwqmLookupMPNService = new MWQMLookupMPNService(query, db, ContactID);
                        mwqmLookupMPNList = (from c in db.MWQMLookupMPNs select c).OrderBy(c => c.MWQMLookupMPNID).Skip(0).Take(2).ToList();
                        count             = (from c in db.MWQMLookupMPNs select c).Count();
                    }

                    if (count > 0)
                    {
                        query.Skip = 0;
                        query.Take = 5;
                        count      = (query.Take > count ? query.Take : count);

                        // ok with MWQMLookupMPN info
                        jsonRet = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take);
                        Assert.IsNotNull(jsonRet);

                        ret = jsonRet as OkNegotiatedContentResult <List <MWQMLookupMPN> >;
                        Assert.AreEqual(mwqmLookupMPNList[0].MWQMLookupMPNID, ret.Content[0].MWQMLookupMPNID);
                        Assert.AreEqual((count > query.Take ? query.Take : count), ret.Content.Count);

                        if (count > 1)
                        {
                            query.Skip = 1;
                            query.Take = 5;
                            count      = (query.Take > count ? query.Take : count);

                            // ok with MWQMLookupMPN info
                            IHttpActionResult jsonRet2 = mwqmLookupMPNController.GetMWQMLookupMPNList(query.Language.ToString(), query.Skip, query.Take);
                            Assert.IsNotNull(jsonRet2);

                            OkNegotiatedContentResult <List <MWQMLookupMPN> > ret2 = jsonRet2 as OkNegotiatedContentResult <List <MWQMLookupMPN> >;
                            Assert.AreEqual(mwqmLookupMPNList[1].MWQMLookupMPNID, ret2.Content[0].MWQMLookupMPNID);
                            Assert.AreEqual((count > query.Take ? query.Take : count), ret2.Content.Count);
                        }
                    }
                }
            }
        }
Ejemplo n.º 37
0
        public async Task <IHttpActionResult> Create(HttpRequestMessage request, [FromBody] CustomerViewModel customerViewModel)
        {
            IHttpActionResult response = null;

            try
            {
                var currentLoggedInUser = UserHelper.GetUserInfo(this);

                Organization newOrganization = (CustomerViewModel)customerViewModel;
                newOrganization.CreatedDateUtc       = DateTime.Now;
                newOrganization.CreatedByID          = currentLoggedInUser.ID;
                newOrganization.ParentOrganizationID = currentLoggedInUser.OrganizationID;
                newOrganization.IsActive             = true;

                switch ((OrganizationType)currentLoggedInUser.OrganizationTypeID)
                {
                case OrganizationType.System:
                    newOrganization.OrganizationTypeID = (int)OrganizationType.Company;
                    break;

                case OrganizationType.Company:
                    newOrganization.OrganizationTypeID = (int)OrganizationType.Customer;
                    break;
                }

                bool success = _customerDataService.Create(newOrganization);

                Guid userID = new Guid();
                if (success)
                {
                    //get admin role ID

                    var roles     = _userDataService.Roles();
                    var adminRole = roles.FirstOrDefault(r => r.IsAdmin);
                    //set user's role and organization datas
                    customerViewModel.AdminUser.Role = new UserRole()
                    {
                        ID = adminRole.ID, IsPrimary = true
                    };
                    customerViewModel.AdminUser.Organization = new UserOrganization()
                    {
                        ID = adminRole.ID, OrganizationID = newOrganization.ID
                    };

                    UserViewModel model = customerViewModel.AdminUser;
                    ////registerUser
                    //var user = UserHelper.CreateCustomIdentityUser(this, model);
                    //var result = await UserManager.CreateAsync(user);
                    //if (result.Succeeded)
                    //{
                    //    await SendPasswordResetEmail(user, true);
                    //    //await SendConfirmationEmail(user);
                    //    response = Ok();
                    //}
                    //else
                    //{
                    //    IHttpActionResult errorResult = GetErrorResult(result);

                    //    if (errorResult != null)
                    //    {
                    //        response = errorResult;
                    //    }
                    //}

                    response = await base.RegisterUser(model);

                    if (response is OkResult || response is OkNegotiatedContentResult <string> )
                    {
                        response = Ok(Resource.CustomerAddedSuccessfully);
                    }

                    //HttpClientHandler handler = new HttpClientHandler
                    //{
                    //    UseCookies = true,
                    //    UseDefaultCredentials = true
                    //};

                    //using (var client = new HttpClient(handler))
                    //{
                    //    HttpResponseMessage responseO;

                    //    client.BaseAddress = new Uri("http://local.pod.com/");



                    //    client.DefaultRequestHeaders.Accept.Clear();
                    //    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    //    responseO = await client.PostAsJsonAsync("api/accounts/Register", customerViewModel.AdminUser);
                    //    if (responseO.IsSuccessStatusCode)
                    //    {
                    //        User user = _userDataService.GetUserByUsername(customerViewModel.AdminUser.UserName);
                    //        userID = user.ID;
                    //    }
                    //}
                    //response = Ok();
                }
                else
                {
                    response = BadRequest();
                }
            }
            catch (Exception e)
            {
                string message = UserHelper.ErrorHandler(e);
                response = ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, message));
            }
            return(response);
        }
Ejemplo n.º 38
0
 public UnauthorizedResult(AuthenticationHeaderValue authHeaderValue, IHttpActionResult innerResult)
 {
     AuthHeaderValue = authHeaderValue;
     InnerResult     = innerResult;
 }
 private static HttpAuthenticationChallengeContext CreateProductUnderTest(HttpActionContext actionContext,
                                                                          IHttpActionResult result)
 {
     return(new HttpAuthenticationChallengeContext(actionContext, result));
 }
 public Task<IHttpActionResult> ChallengeAsync(HttpActionContext context, IHttpActionResult innerResult,
     CancellationToken cancellationToken)
 {
     ExceptionTestsUtility.CheckForThrow(_throwAt, "AuthenticationChallenge");
     return Task.FromResult(innerResult);
 }
        public void Contact_Controller_Post_Test()
        {
            foreach (LanguageEnum LanguageRequest in AllowableLanguages)
            {
                foreach (int ContactID in new List <int>()
                {
                    AdminContactID
                })                                                             //, TestEmailValidatedContactID, TestEmailNotValidatedContactID })
                {
                    ContactController contactController = new ContactController(DatabaseTypeEnum.SqlServerTestDB);
                    Assert.IsNotNull(contactController);
                    Assert.AreEqual(DatabaseTypeEnum.SqlServerTestDB, contactController.DatabaseType);

                    Contact contactLast = new Contact();
                    using (CSSPDBContext db = new CSSPDBContext(DatabaseType))
                    {
                        Query query = new Query();
                        query.Language = LanguageRequest;
                        query.Asc      = "";
                        query.Desc     = "";

                        ContactService contactService = new ContactService(query, db, ContactID);
                        contactLast = (from c in db.Contacts select c).FirstOrDefault();
                    }

                    // ok with Contact info
                    IHttpActionResult jsonRet = contactController.GetContactWithID(contactLast.ContactID);
                    Assert.IsNotNull(jsonRet);

                    OkNegotiatedContentResult <Contact> Ret = jsonRet as OkNegotiatedContentResult <Contact>;
                    Contact contactRet = Ret.Content;
                    Assert.AreEqual(contactLast.ContactID, contactRet.ContactID);

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

                    // Post to return CSSPError because ContactID exist
                    IHttpActionResult jsonRet2 = contactController.Post(contactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet2);

                    OkNegotiatedContentResult <Contact> contactRet2 = jsonRet2 as OkNegotiatedContentResult <Contact>;
                    Assert.IsNull(contactRet2);

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

                    // Post to return newly added Contact
                    contactRet.ContactID                 = 0;
                    contactController.Request            = new System.Net.Http.HttpRequestMessage();
                    contactController.Request.RequestUri = new System.Uri("http://localhost:5000/api/contact");
                    IHttpActionResult jsonRet3 = contactController.Post(contactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet3);

                    CreatedNegotiatedContentResult <Contact> contactRet3 = jsonRet3 as CreatedNegotiatedContentResult <Contact>;
                    Assert.IsNotNull(contactRet3);

                    BadRequestErrorMessageResult badRequest3 = jsonRet3 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest3);

                    IHttpActionResult jsonRet4 = contactController.Delete(contactRet, LanguageRequest.ToString());
                    Assert.IsNotNull(jsonRet4);

                    OkNegotiatedContentResult <Contact> contactRet4 = jsonRet4 as OkNegotiatedContentResult <Contact>;
                    Assert.IsNotNull(contactRet4);

                    BadRequestErrorMessageResult badRequest4 = jsonRet4 as BadRequestErrorMessageResult;
                    Assert.IsNull(badRequest4);
                }
            }
        }
 private static HttpAuthenticationChallengeContext CreateProductUnderTest(HttpActionContext actionContext,
     IHttpActionResult result)
 {
     return new HttpAuthenticationChallengeContext(actionContext, result);
 }
 public WrappedHttpActionResult(IHttpActionResult inner, string responsePhrase, Action<HttpResponseMessage> responseAction = null)
 {
     _innerResult = inner;
     _responsePhrase = responsePhrase;
     _responseAction = responseAction;
 }
Ejemplo n.º 44
0
 public AddChallengeOnUnauthorizedResult(AuthenticationHeaderValue challenge, IHttpActionResult innerResult)
 {
     _challenge = challenge;
     _innerResult = innerResult;
 }
 private static AuthenticationFilterResult CreateProductUnderTest(HttpActionContext context,
     ApiController controller, IAuthenticationFilter[] filters, IHttpActionResult innerResult)
 {
     return new AuthenticationFilterResult(context, controller, filters, innerResult);
 }
Ejemplo n.º 46
0
        public void Given_A_Location_When_Service_Called_Then_Return_All_Documents_From_Location()
        {
            _actionResult = _controller.GetStationeryDocumentsByLocation("barney");
            Assert.IsInstanceOf<OkNegotiatedContentResult<List<Document>>>(_actionResult);

            OkNegotiatedContentResult<List<Document>> contentResult = _actionResult as OkNegotiatedContentResult<List<Document>>;
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);

            var documents = contentResult.Content;
            Assert.AreEqual(_barneyDocuments.Count, documents.Count);
        }
 public AuthenticationChallengeResult(AuthenticationHeaderValue challenge, IHttpActionResult innerResult)
 {
     Challenge = challenge;
     InnerResult = innerResult;
 }
Ejemplo n.º 48
0
 private static ExceptionFilterResult CreateProductUnderTest(HttpActionContext context, IExceptionFilter[] filters,
                                                             IExceptionLogger exceptionLogger, IExceptionHandler exceptionHandler, IHttpActionResult innerResult)
 {
     return(new ExceptionFilterResult(context, filters, exceptionLogger, exceptionHandler, innerResult));
 }
 public ResultWithChallenge(IHttpActionResult next)
 {
     this.next = next;
 }
Ejemplo n.º 50
0
        public void FailIfSinglePaymentIdDoesntExistInRepository()
        {
            IHttpActionResult actionResult = CONTROLLER.GetPayment(0);

            Assert.IsInstanceOfType(actionResult, typeof(NotFoundResult));
        }
Ejemplo n.º 51
0
        public void Given_A_Document_Id_When_Service_Called_Then_Return_The_Document()
        {
            _actionResult = _controller.GetStationeryDocumentById(123);
            Assert.IsInstanceOf<OkNegotiatedContentResult<Document>>(_actionResult);

            OkNegotiatedContentResult<Document> contentResult = _actionResult as OkNegotiatedContentResult<Document>;
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);

            var document = contentResult.Content;
            Assert.AreEqual(_contentDocument.Content.Length, document.Content.Length);

            // found this here: http://stackoverflow.com/questions/347818/using-moq-to-determine-if-a-method-is-called/347907#347907
            // does it make sense to anyone? apparently it just verifies the methods was called?
            // _mockDocumentService.Verify(m => m.GetDocumentById((1)));
        }
Ejemplo n.º 52
0
        public void FailIfPostedNewPaymentIsAlreadyInRepository()
        {
            IHttpActionResult actionResult = CONTROLLER.PostPayment(FIRST_PAYMENT);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult));
        }
Ejemplo n.º 53
0
        public void Given_List_Of_Locations_Exists_When_Service_Called_Then_Locations_Returned()
        {
            _actionResult = _controller.GetStationeryLocations();
            Assert.IsInstanceOf<OkNegotiatedContentResult<List<string>>>(_actionResult);

            OkNegotiatedContentResult<List<string>> contentResult = _actionResult as OkNegotiatedContentResult<List<string>>;
            Assert.IsNotNull(contentResult);
            Assert.IsNotNull(contentResult.Content);

            var locations = contentResult.Content;

            Assert.AreEqual(_locations.Count, locations.Count);
        }
        public async Task ReturnOkResultWhenDeleteAllAsync()
        {
            IHttpActionResult result = await AssumeDeleteAllAsync().ConfigureAwait(false);

            _ = result.Should().BeAssignableTo <OkResult>("DeleteAllAsync did not return OkResult");
        }
 public ResultWithChallenge(IHttpActionResult next, string realm, string opaque)
 {
     this.next   = next;
     this.realm  = realm;
     this.opaque = opaque;
 }
Ejemplo n.º 56
0
        public async Task TestUsersApiPostAsync()
        {
            // Arrange
            int actualUserCount = 0;

            // Act
            IHttpActionResult userResult = controller.Get();
            var message = await userResult.ExecuteAsync(new System.Threading.CancellationToken());

            var users = await message.Content.ReadAsAsync <IEnumerable <User> >();

            foreach (var user in users)
            {
                actualUserCount++;
            }

            //////////////////////////////////////////////////////////////////

            // Post -- invalid model -- expect bad request message
            User newUser = new User();

            newUser.Username = "******";
            //newUser.Password = "******";
            newUser.Email = "*****@*****.**";
            newUser.Id    = new Guid("55555555-4444-4444-4444-222222222222");

            controller.ModelState.AddModelError("k1", "password is too short");
            IHttpActionResult result = controller.Post(new UserAPI(newUser));
            var badPostMessage       = await result.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.BadRequest, badPostMessage.StatusCode);

            //newUser.Password = "******";
            controller.ModelState.Remove("k1");
            IHttpActionResult goodResult = controller.Post(new UserAPI(newUser));
            var goodPostMessage          = await goodResult.ExecuteAsync(new System.Threading.CancellationToken());

            Assert.AreEqual(HttpStatusCode.OK, goodPostMessage.StatusCode);

            /////////////////////////////////////////////////////////////////

            // Arrange
            int expectedUserCount = actualUserCount + 1;

            // reset count to test again after the POST
            actualUserCount = 0;

            // Act
            userResult = controller.Get();
            message    = await userResult.ExecuteAsync(new System.Threading.CancellationToken());

            users = await message.Content.ReadAsAsync <IEnumerable <User> >();

            foreach (var user in users)
            {
                actualUserCount++;
            }

            // Assert
            Assert.AreEqual(expectedUserCount, actualUserCount);
        }
 Task<IHttpActionResult> IAuthenticationFilter.ChallengeAsync(HttpActionContext context, IHttpActionResult result, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 58
0
 protected override void When()
 {
     _result = SUT.Update(ExistingItemName, newQuantity);
 }
        internal bool EvaluateRequestedDateTime(string requestedDatetimeString, out DateTime parsed, out IHttpActionResult badRequest)
        {
            if (!requestedDatetimeString.TryParseIso8061Basic(out parsed))
            {
                badRequest = BadRequest(String.Format("'{0}' could not be interpreted as an UTC ISO 8061 basic formatted DateTime.", requestedDatetimeString));
                return false;
            }

            if (parsed < _sensorEventsService.GetMaxLifetime().Since)
            {
                badRequest = BadRequest("The provided datetime was earlier than the maximum allowed lifetime.");
                return false;
            }

            badRequest = null;
            return true;
        }
Ejemplo n.º 60
0
        public IHttpActionResult GetBooks(string year)
        {
            IHttpActionResult lResult = null;
            var lLogMsg     = string.Empty;
            var lstBooks    = new List <BookViewModel>();
            var userId      = User.Identity.GetUserId();
            int?publisherID = 0;
            var lCookieData = new CustomPrincipalSerializerModel();

            try
            {
                using (Loreal_DEVEntities5 db = new Loreal_DEVEntities5())
                {
                    publisherID = db.AspNetUsers
                                  .Where(a => a.Id == userId)
                                  .Select(a => a.PublisherID)
                                  .SingleOrDefault();
                }

                // Update Cookie
                lCookieData.Id          = userId;
                lCookieData.Year        = year;
                lCookieData.PublisherID = publisherID;
                lCookieData.Publisher   = CookieManagement.GetPublisher(publisherID);
                var lbool = CookieManagement.UpdateCookie(System.Web.HttpContext.Current, User, lCookieData);

                // We're in a weird zombie cookie state.  Logoff.
                //if (!lbool)
                //{
                //    //return Redirect("/Account/LogOff");
                //    var newUrl = this.Url.Link("Default", new
                //    {
                //        Controller = "Account",
                //        Action = "LogOff"
                //    });
                //    return Request.CreateResponse(HttpStatusCode.OK, new { Success = true, RedirectUrl = newUrl });
                //}

                using (Loreal_DEVEntities4 db = new Loreal_DEVEntities4())
                {
                    var books = db.Books
                                .Where(b => b.Year == year && b.PublisherID == publisherID)
                                .OrderBy(b => b.Book1)
                                .ToList();

                    if (books.Any())
                    {
                        foreach (var book in books)
                        {
                            var lbook = new BookViewModel();
                            lbook.ID   = book.BookID;
                            lbook.Name = book.Book1;

                            lstBooks.Add(lbook);
                        }
                        lResult = Ok(lstBooks);
                    }
                    else
                    {
                        lResult = Ok();
                    }
                }
            }
            catch (Exception ex)
            {
                var lReturnMessage = String.Format("Error in GetBooks. Year: {0} Publisher: {1}, Book: {2}, BookID: {3}.", year, lCookieData.Publisher, lCookieData.Book, lCookieData.BookID);
                lLogMsg = String.Format(lReturnMessage + "ERROR MESSAGE: {0}.  SOURCE: {1}. STACKTRACE: {2}.", ex.Message, ex.Source, ex.StackTrace);
                logger.Error(lLogMsg);
                lResult = BadRequest(lReturnMessage);
            }
            return(lResult);
        }