Beispiel #1
0
 public void Setup()
 {
     User = new User
     {
         Passes = new List <Pass>
         {
             new ClipPass
             {
                 ClipsRemaining = 0,
                 EndDate        = DateTime.Now.AddDays(4)
             },
             new Pass
             {
                 EndDate = DateTime.Now.AddDays(-2)
             }
         }
     };
     PassTemplate = new PassTemplate
     {
         PassType = PassType.Unlimited.ToString()
     };
     Pass = new Pass();
     ClassRepositoryBuilder = new MockRepositoryBuilder <Class>()
                              .WithGetAll();
 }
 public void Setup()
 {
     _existingBlock = new Block
     {
         Name      = "old",
         StartDate = DateTime.MaxValue,
         EndDate   = DateTime.MaxValue,
         Teachers  = new List <Teacher> {
             new Teacher {
                 Id = 1
             }
         },
         Classes = new Collection <Class>()
     };
     _action = new UpdateBlock(new Block
     {
         Name      = "new",
         StartDate = DateTime.MinValue.AddYears(1).Date,
         EndDate   = DateTime.MinValue.AddYears(1).Date,
         Teachers  = new List <Teacher> {
             new Teacher {
                 Id = 1
             }
         }
     });
     _repositoryBuilder = new MockRepositoryBuilder <Block>()
                          .WithGet(_existingBlock)
                          .WithUpdate();
     _teacherRepositoryBuilder = new MockRepositoryBuilder <Teacher>()
                                 .WithSuccessfulGet();
 }
Beispiel #3
0
 public void Setup()
 {
     _existingPass = new Pass
     {
         EndDate = DateTime.Now.AddDays(4)
     };
     _pendingPass = new Pass
     {
         StartDate = DateTime.Now.AddDays(5),
         EndDate   = DateTime.Now.AddDays(10)
     };
     User = new User
     {
         Passes = new List <Pass>
         {
             _existingPass,
             _pendingPass
         }
     };
     PassTemplate = new PassTemplate
     {
         PassType = PassType.Unlimited.ToString()
     };
     Pass = new Pass();
     ClassRepositoryBuilder = new MockRepositoryBuilder <Class>()
                              .WithGetAll();
 }
Beispiel #4
0
        public void Setup()
        {
            _userRepositoryBuilder = new MockRepositoryBuilder <User>()
                                     .WithSuccessfulGet()
                                     .WithUpdate();
            _blockRepositoryBuilder = new MockRepositoryBuilder <Block>()
                                      .WithGetAll(new [] {
                new Block
                {
                    Classes = new List <Class>()
                }
            });

            _action = new EnrolInBlock(new User
            {
                Id            = 5,
                Passes        = new List <Pass>(),
                EnroledBlocks = new List <Block>
                {
                    new Block
                    {
                        Id = 10
                    }
                }
            });
            _bookingRepositoryBuilder = new MockRepositoryBuilder <Class>()
                                        .WithCreate()
                                        .WithGetAll();
            _postOfficeBuilder = new MockPostOfficeBuilder()
                                 .WithSending();
        }
Beispiel #5
0
        public void SetUp()
        {
            // you have to be an administrator to access the product controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            categoryRepository = MockRepositoryBuilder.CreateCategoryRepository();

            productRepository = MockRepositoryBuilder.CreateProductRepository();

            productOrderableService = MockRepository.GenerateStub<IOrderableService<ProductCategory>>();
            MockRepository.GenerateStub<IOrderableService<ProductImage>>();

        	userService = MockRepository.GenerateStub<IUserService>();
            productBuilder = MockRepository.GenerateStub<IProductBuilder>();

			productController = new ProductController(
                productRepository, 
                categoryRepository, 
                productOrderableService, 
                userService, 
                MockRepository.GenerateStub<IUnitOfWorkManager>(),
                productBuilder);

        	userService.Stub(c => c.CurrentUser).Return(new User { Role = Role.Administrator });
        }
Beispiel #6
0
 public virtual void Setup()
 {
     _existingClass = new Class
     {
         Name      = "old",
         StartTime = DateTime.MaxValue,
         EndTime   = DateTime.MaxValue,
         Teachers  = new List <Teacher>
         {
             new Teacher {
                 Id = 1
             }
         }
     };
     _action = new UpdateClass(new Class
     {
         Name      = "new",
         StartTime = DateTime.MinValue.AddYears(1).Date,
         EndTime   = DateTime.MinValue.AddYears(1).Date,
         Teachers  = new List <Teacher>
         {
             new Teacher {
                 Id = 1
             }
         }
     });
     _repositoryBuilder = new MockRepositoryBuilder <Class>()
                          .WithGet(_existingClass)
                          .WithUpdate();
     _teacherRepositoryBuilder = new MockRepositoryBuilder <Teacher>()
                                 .WithSuccessfulGet();
 }
Beispiel #7
0
 public void Setup()
 {
     _retrievedClass = new Class
     {
         ActualStudents = new List <User>()
     };
     _classRepositoryBuilder = new MockRepositoryBuilder <Class>()
                               .WithGet(_retrievedClass);
     _retrievedUser = new User
     {
         Passes = new List <Pass>
         {
             new Pass
             {
                 StartDate     = DateTime.Now.AddDays(-1),
                 EndDate       = DateTime.Now.AddDays(1),
                 PaymentStatus = PassPaymentStatus.Paid.ToString()
             }
         }
     };
     _userRepositoryBuilder = new MockRepositoryBuilder <User>()
                              .WithGet(_retrievedUser);
     _class = new Class
     {
         Id             = 12,
         ActualStudents = new List <User>
         {
             new User()
         }
     };
 }
 public virtual void Setup()
 {
     UserInDatabase = new User
     {
         Passes = new List <Pass>
         {
             new Pass
             {
                 PassStatistic = new PassStatistic()
             }
         }
     };
     ClassInDatabase        = new Class();
     ClassRepositoryBuilder = new MockRepositoryBuilder <Class>()
                              .WithGet(ClassInDatabase)
                              .WithUpdate();
     UserRepositoryBuilder = new MockRepositoryBuilder <User>()
                             .WithGet(UserInDatabase);
     Action = new CheckStudentIntoClass(new Class
     {
         ActualStudents = new List <User>
         {
             new User()
         }
     });
 }
Beispiel #9
0
        public async Task DeleteCustomer_AcceptedTestAsync()
        {
            var queryCustomerById = @"SELECT Id, AddressId, Name, DateCreated
                          FROM dbo.Customer c
                          WHERE c.Id = @Id";

            List <Customer> customerModel = CustomerMock.CustomerModelFaker.Generate(1);

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <Customer>(
                                                                             queryCustomerById,
                                                                             It.IsAny <object>(),
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(customerModel);

            MockAuthorizationFactory.AddAdminHeaders(_httpClient);

            var customer = CustomerMock.CustomerViewModelFaker.Generate();

            customer.Id = customerModel[0].Id;

            var response = await _httpClient.DeleteAsync($"/api/v1/customers/{customerModel[0].Id}");

            Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
        }
Beispiel #10
0
        public void MapToViewData_should_map_category_entities_to_view_data()
        {
            var categories         = MockRepositoryBuilder.CreateCategoryRepository().GetAll();
            var viewDataCategories = categories.MapToViewData();

            var rootCategory = viewDataCategories.GetRoot();

            Assert.That(rootCategory.Name, Is.EqualTo("root"));
            Assert.That(rootCategory.ChildCategories.Count, Is.EqualTo(2), "root has no children");

            var one = rootCategory.ChildCategories[0];
            var two = rootCategory.ChildCategories[1];

            Assert.That(one.Name, Is.EqualTo("one"));
            Assert.That(two.Name, Is.EqualTo("two"));

            Assert.That(one.ChildCategories.Count, Is.EqualTo(2), "one has no children");
            var oneOne = one.ChildCategories[0];
            var oneTwo = one.ChildCategories[1];

            Assert.That(oneOne.Name, Is.EqualTo("oneOne"));
            Assert.That(oneTwo.Name, Is.EqualTo("oneTwo"));

            Assert.That(oneTwo.ChildCategories.Count, Is.EqualTo(2), "oneTwo has no children");
            var oneTwoOne = oneTwo.ChildCategories[0];
            var oneTwoTwo = oneTwo.ChildCategories[1];

            Assert.That(oneTwoOne.Name, Is.EqualTo("oneTwoOne"));
            Assert.That(oneTwoTwo.Name, Is.EqualTo("oneTwoTwo"));
        }
        public void Crud_EntityTest()
        {
            var customer = CustomerMock.CustomerModelFaker.Generate();

            _configurationMock.Setup(x => x.GetSection(It.IsAny <string>()))
            .Returns(new Mock <IConfigurationSection>().Object);

            var entityContext      = new EntityContext(_entityOptions);
            var unitOfWork         = new UnitOfWork(entityContext);
            var dapperContext      = new DapperContext(MockRepositoryBuilder.GetMockDbConnection().Object);
            var customerRepository = new CustomerRepository(entityContext, dapperContext);

            customerRepository.Add(customer);
            var IsSaveCustomer = unitOfWork.Commit();

            customerRepository.Update(customer);
            var IsUpdateCustomer = unitOfWork.Commit();

            customerRepository.Remove(customer);
            var IsRemoverCustomer = unitOfWork.Commit();

            Assert.Equal(1, IsSaveCustomer);
            Assert.Equal(1, IsUpdateCustomer);
            Assert.Equal(1, IsRemoverCustomer);
        }
Beispiel #12
0
        protected void SetupDependencies()
        {
            RepositoryBuilder = new MockRepositoryBuilder <TEntity>()
                                .WithCreate();

            AppSettingsBuilder = new MockAppSettingsBuilder()
                                 .WithAllSettings();
        }
Beispiel #13
0
            public void When_pass_template_doesnt_exist()
            {
                RepositoryBuilder = new MockRepositoryBuilder <PassTemplate>()
                                    .WithUnsuccessfulGet();

                var result = PerformAction();

                ExpectValidationError(result, ValidationMessages.ItemDoesntExist);
            }
 public void Setup()
 {
     _savedPass             = new Pass();
     _passRepositoryBuilder = new MockRepositoryBuilder <Pass>().WithGet(_savedPass);
     _pass = new Pass
     {
         StartDate = DateTime.Now.AddDays(-1),
         EndDate   = DateTime.Now.AddDays(2),
     };
 }
 public void Setup()
 {
     _userRepositoryBuilder = new MockRepositoryBuilder <User>().WithUnsuccessfulGet();
     _user = new User
     {
         Email     = "*****@*****.**",
         Password  = "******",
         Surname   = "Chappers",
         FirstName = "Bob"
     };
 }
Beispiel #16
0
 public void Setup()
 {
     User         = new User();
     PassTemplate = new PassTemplate
     {
         PassType = PassType.Unlimited.ToString()
     };
     Pass = new Pass();
     ClassRepositoryBuilder = new MockRepositoryBuilder <Class>()
                              .WithGetAll();
 }
Beispiel #17
0
        public void Setup()
        {
            Parameter = new PassTemplate {
                Id = 1
            };

            RepositoryBuilder = new MockRepositoryBuilder <PassTemplate>()
                                .WithGet(new PassTemplate {
                Id = 1
            });
        }
Beispiel #18
0
        public void SetUp()
        {
            categoryRepository = MockRepositoryBuilder.CreateCategoryRepository();
            orderableService   = MockRepository.GenerateStub <IOrderableService <Category> >();
            fileService        = MockRepository.GenerateStub <IHttpFileService>();
            imageRepository    = MockRepository.GenerateStub <IRepository <Image> >();

            categoryController = new CategoryController(
                categoryRepository,
                orderableService,
                fileService,
                imageRepository
                );
        }
Beispiel #19
0
        public void Setup()
        {
            context = new AuthorizationContext
            {
                HttpContext = new TestControllerBuilder().HttpContext
            };

            userRepositoryFactory = MockRepository.GenerateStub <IRepositoryFactory <User> >();
            userRepository        = MockRepositoryBuilder.CreateUserRepository();
            userRepositoryFactory.Stub(x => x.Resolve()).Return(userRepository).Repeat.Any();

            formsAuth = MockRepository.GenerateStub <IFormsAuthentication>();
            filter    = new AuthenticateFilter(formsAuth, userRepositoryFactory);

            originalPrincipal = Thread.CurrentPrincipal;
        }
 public void Setup()
 {
     _repositoryBuilder = new MockRepositoryBuilder <Block>()
                          .WithSuccessfulGet();
     _teacherRepositoryBuilder = new MockRepositoryBuilder <Teacher>()
                                 .WithGet(new Teacher());
     Parameter = new Block
     {
         Name     = "name",
         Teachers = new List <Teacher> {
             new Teacher()
             {
                 Id = 1
             }
         }
     };
 }
Beispiel #21
0
        private void Arrange()
        {
            var queryCustomers = @"SELECT c.Id AS id, a.Id AS addressId, c.Name AS name, c.DateCreated AS dateCreated, a.CEP AS cep
                            FROM dbo.Customer c
                            INNER JOIN dbo.Address a
                            ON c.addressId = a.Id";

            List <CustomerAddress> customers = CustomerMock.CustomerAddressModelFaker.Generate(6);

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <CustomerAddress>(
                                                                             queryCustomers,
                                                                             null,
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(customers);


            var queryCustomerAddressByName = @"SELECT c.Id AS id, a.Id AS addressId, c.Name AS name, c.DateCreated AS dateCreated, a.CEP AS cep
                          FROM dbo.Customer c
                          INNER JOIN dbo.Address a
                          ON c.addressId = a.Id
                          WHERE c.Name = @Name";

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <CustomerAddress>(
                                                                             queryCustomerAddressByName,
                                                                             It.IsAny <object>(),
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(() => new List <CustomerAddress>());



            var queryCustomerById = @"SELECT Id, AddressId, Name, DateCreated
                          FROM dbo.Customer c
                          WHERE c.Id = @Id";

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <Customer>(
                                                                             queryCustomerById,
                                                                             It.IsAny <object>(),
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(new List <Customer>());
        }
Beispiel #22
0
        public void SetUp()
        {
            // you have to be an administrator to access the user controller
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("admin"), new[] { "Administrator" });

            userRepository = MockRepositoryBuilder.CreateUserRepository();

            var roleRepository = MockRepositoryBuilder.CreateRoleRepository();

            userService = MockRepository.GenerateStub <IUserService>();
            userService.Stub(x => x.HashPassword(Arg <string> .Is.Anything)).Do(new Func <string, string>(s => s + "HASHED"));

            userController = new UserController(userRepository, roleRepository, userService);
            testContext    = new ControllerTestContext(userController);


            // setup the querystring to return an empty name value collection by default
            testContext.TestContext.Request.Expect(r => r.QueryString).Return(new NameValueCollection());
        }
        public void Setup()
        {
            var teacher = new Teacher();

            _repositoryBuilder = new MockRepositoryBuilder <Class>()
                                 .WithSuccessfulGet();
            Parameter = new Class
            {
                Name      = "name",
                EndTime   = DateTime.Now.AddMinutes(60),
                StartTime = DateTime.Now.AddMinutes(40),
                Teachers  = new List <Teacher>
                {
                    teacher
                }
            };
            _teacherRepositoryBuilder = new MockRepositoryBuilder <Teacher>()
                                        .WithGet(teacher);
        }
        public void Setup()
        {
            product = new Product
            {
                Reviews =
                {
                    new Review(),
                    new Review()
                }
            };

            productRepository = new FakeRepository <Product>(id =>
            {
                product.Id = id;
                return(product);
            });

            reviewRepository = MockRepositoryBuilder.CreateReviewRepository();

            commentRepository = MockRepository.GenerateStub <IRepository <IComment> >();

            var comments = new List <IComment>
            {
                new Comment {
                    Approved = true
                },
                new Comment {
                    Approved = false
                },
                new Review {
                    Approved = true
                },
                new Comment {
                    Approved = true
                }
            }.AsQueryable();

            commentRepository.Stub(r => r.GetAll()).Return(comments);

            controller = new ReviewsController(reviewRepository, productRepository, commentRepository);
        }
Beispiel #25
0
        public async Task PostCustomer_BadRequesTestAsync()
        {
            var queryCustomerAddressByName = @"SELECT c.Id AS id, a.Id AS addressId, c.Name AS name, c.DateCreated AS dateCreated, a.CEP AS cep
                          FROM dbo.Customer c
                          INNER JOIN dbo.Address a
                          ON c.addressId = a.Id
                          WHERE c.Name = @Name";

            List <CustomerAddress> customerAddressByName = CustomerMock.CustomerAddressModelFaker.Generate(1);

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <CustomerAddress>(
                                                                             queryCustomerAddressByName,
                                                                             It.IsAny <object>(),
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(customerAddressByName);

            MockAuthorizationFactory.AddAdminHeaders(_httpClient);
            var customer = CustomerMock.CustomerViewModelFaker.Generate();

            customer.Id   = customerAddressByName[0].Id;
            customer.Name = customerAddressByName[0].Name;

            HttpRequestMessage request = new HttpRequestMessage
            {
                RequestUri = new System.Uri($"{this._httpClient.BaseAddress.OriginalString}/api/v1/customers"),
                Method     = new HttpMethod("Post"),
                Headers    = { { "User-Agent", "csharp" } },
                Content    = new StringContent(JsonConvert.SerializeObject(customer),
                                               Encoding.UTF8,
                                               "application/json")
            };

            var response = await this._httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead);


            string message = await response.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
        }
        private static IServiceProvider InitializeServiceProvider(IServiceCollection services)
        {
            services
            .AddEntityFrameworkInMemoryDatabase()
            .AddDbContext <EntityContext>(
                options =>
            {
                options.UseInMemoryDatabase("InMemoryDbForTesting");
                //     .ConfigureWarnings(
                //         x => x.Ignore(InMemoryEventId.TransactionIgnoredWarning)
                //     );
                // options.UseInternalServiceProvider(services.BuildServiceProvider());
            }
                );

            services.AddSingleton <DapperContext>(sp =>
            {
                return(new DapperContext(MockRepositoryBuilder.GetMockDbConnection().Object));
            });

            services.PostConfigure <JwtBearerOptions>(
                JwtBearerDefaults.AuthenticationScheme,
                options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    SignatureValidator       = (token, parameters) => new JwtSecurityToken(token),
                    ValidateIssuer           = false,
                    ValidateLifetime         = false,
                    ValidateIssuerSigningKey = false,
                    ValidateAudience         = false,
                };

                options.Configuration = new OpenIdConnectConfiguration();
            });


            return(services.BuildServiceProvider());;
        }
Beispiel #27
0
        public async Task GetById_OKTestAsync()
        {
            var queryCustomerAddressById = @"SELECT c.Id, a.Id AS AddressId, c.Name, c.DateCreated, a.CEP
                          FROM dbo.Customer c
                          INNER JOIN dbo.Address a
                          ON c.AddressId = a.Id
                          WHERE c.Id = @Id";

            List <CustomerAddress> customerAddressById = CustomerMock.CustomerAddressModelFaker.Generate(1);

            MockRepositoryBuilder.GetMockDbConnection().SetupDapperAsync(c => c.QueryAsync <CustomerAddress>(
                                                                             queryCustomerAddressById,
                                                                             It.IsAny <object>(),
                                                                             null,
                                                                             null,
                                                                             null)).ReturnsAsync(customerAddressById);

            MockAuthorizationFactory.AddAdminHeaders(_httpClient);

            var response = await _httpClient.GetAsync("/api/v1/customers/1");

            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
 public void Setup()
 {
     controller = new RichEditorController(MockRepositoryBuilder.CreateProductRepository(), MockRepositoryBuilder.CreateCategoryRepository(), MockRepositoryBuilder.CreateContentRepository());
 }