示例#1
0
        public async Task Authorize_ExpectSuccessResponse()
        {
            // Arrange
            await uow.AccountRepository.Add(new Account()
            {
                Login    = "******",
                Nickname = "AlexAnder",
                Password = Shared.Utils.HashString("12345678asdf"),
                Role     = Account.Roles.User,
            });

            await uow.SaveChanges();

            var command = new AuthorizeAccountCommand()
            {
                Login    = "******",
                Password = "******",
            };

            var mockQueryFactory = new Mock <IQueryFactory>();

            mockQueryFactory.Setup(repo => repo.ResolveQuery <AccountByLoginAndPasswordQuery>())
            .Returns(() => new AccountByLoginAndPasswordQuery(uow));

            // Act
            var controller = new AccountController(null, mockQueryFactory.Object, mapper, new AccountApiService(mapper));
            await controller.Authorize(command);

            // Assert
            Assert.Pass();
        }
示例#2
0
        public object Create(string values)
        {
            var articol = new CrmArticole();

            JsonConvert.PopulateObject(values, articol);

            if (!TryValidateModel(articol))
            {
                return(BadRequest(ModelState.IsValid));
            }

            try
            {
                appUnitOfWork.crmArticoleRepo.Add(articol);
                appUnitOfWork.SaveChanges();
                return(Json(new { status = 1, count = 1 }));
            }
            catch (Exception ex)
            {
                //TODO - nlog.e.Message!
                return(BadRequest(ex.Message));
            }
        }