示例#1
0
        public async Task Delete_CategoryWithProducts_ShouldDeleteCategory()
        {
            // .Arrange
            Category category = new Category()
            {
                CategoryName = Guid.NewGuid().ToString()
            };

            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                await context.AddAsync(category);

                await context.SaveChangesAsync();

                await context.AddAsync(new Product()
                {
                    CategoryId = category.Id, Title = Guid.NewGuid().ToString()
                });

                await context.SaveChangesAsync();
            }

            // .Act
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                await sut.DeleteAsync(category.Id);
            }
            // .Assert
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                Assert.IsNull(context.Find <Category>(category.Id));
            }
        }
示例#2
0
        public async Task Create_DuplicatedCategory_ShouldThrowException()
        {
            // .Arrange
            Category category = new Category()
            {
                CategoryName = "DUPLICATED"
            };

            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                await context.AddAsync(category);

                await context.SaveChangesAsync();
            }
            var duplicatedCatgory = new Category()
            {
                CategoryName = category.CategoryName
            };

            // .Assert
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                Assert.That(async() =>
                            // .Act
                            await sut.CreateAsync(duplicatedCatgory), Throws.Exception);
            }
        }
示例#3
0
        public void ContextBuildsAViewModelWithAllCategories()
        {
            var category = new Category {
                Description = "Category 1"
            };
            var categoryViewModel = new CategoryViewModel {
                Description = "Category 1"
            };
            var categories = new List <Category> {
                category
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetAllToReturn(categories);
            var mockCategoryMapper     = new MockCategoryMapper().StubMapToReturn(categoryViewModel);
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoriesContext.BuildViewModel();

            Assert.NotNull(viewModel);
            Assert.IsType <CategoriesViewModel>(viewModel);
            Assert.Equal(categories.Count, viewModel.Categories.Count());

            var categoryViewModels = viewModel.Categories.ToList();

            Assert.Equal(category.Id, categoryViewModels.First()
                         .Id);
            Assert.Equal(category.Description, categoryViewModels.First()
                         .Description);

            mockCategoryRepository.VerifyGetAllCalled();
            mockCategoryMapper.VerifyMapCalledWith(category);
        }
示例#4
0
        public void CreatesACategoriesContext()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            Assert.NotNull(categoriesContext);
        }
示例#5
0
 public async Task Delete_NotExistingCategory_ShouldThrowException()
 {
     // .Assert
     using (var context = CategoriesContext.GetLinnworksIntegrationContext())
     {
         var sut = new GenericRepository <Category>(context);
         Assert.That(async() =>
                     // .Act
                     await sut.DeleteAsync(Guid.NewGuid()), Throws.Exception);
     }
 }
示例#6
0
        public void ContextBuildsAViewModel()
        {
            var mockCategoryRepository = new MockCategoryRepository();
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            var viewModel = categoriesContext.BuildViewModel();

            Assert.NotNull(viewModel);
            Assert.IsType <CategoriesViewModel>(viewModel);
        }
示例#7
0
 public void Update_ExistingCategory_ShouldNotThrowException()
 {
     // .Assert
     using (var context = CategoriesContext.GetLinnworksIntegrationContext())
     {
         var sut = new GenericRepository <Category>(context);
         Assert.That(async() =>
                     // .Act
                     await sut.UpdateAsync(Guid.NewGuid(), new Category()
         {
             CategoryName = Guid.NewGuid().ToString()
         }), Throws.Nothing);
     }
 }
示例#8
0
        public void ContextRemovesACategory()
        {
            var category = new Category {
                Description = "Category 2"
            };
            var mockCategoryRepository = new MockCategoryRepository().StubGetByIdToReturn(category);
            var mockCategoryMapper     = new MockCategoryMapper();
            var categoriesContext      = new CategoriesContext(mockCategoryRepository, mockCategoryMapper);

            categoriesContext.Remove(category.Id);

            mockCategoryRepository.VerifyGetByCalledWith(category.Id);
            mockCategoryRepository.VerifyRemoveCalledWith(category);
        }
示例#9
0
        public async Task GetAll_Categories_Returns_True()
        {
            object AllCategories;

            // .Arrange
            // .Act
            using (var context = CategoriesContext.GetLinnworksIntegrationContext())
            {
                var sut = new GenericRepository <Category>(context);
                AllCategories = await sut.GetAllAsync();
            }

            // .Assert
            Assert.NotNull(AllCategories);
        }
示例#10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var config = new ServerConfig();

            Configuration.Bind(config);

            var newsContext       = new NewsContext(config.MongoDB);
            var newsRepo          = new NewsRepository(newsContext);
            var categoriesContext = new CategoriesContext(config.MongoDB);
            var categoriesRepo    = new CategoriesRepository(categoriesContext);
            var imagesContext     = new ImagesContext(config.MongoDB);
            var imagesRepo        = new ImagesRepository(imagesContext);

            services.AddSingleton <INewsRepository>(newsRepo);
            services.AddSingleton <ICategoriesRepository>(categoriesRepo);
            services.AddSingleton <IImagesRepository>(imagesRepo);

            services.AddCors(options =>
            {
                options.AddPolicy(SpecificOrigins,
                                  builder =>
                {
                    builder.WithOrigins("http://localhost",
                                        "http://localhost:3000").AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod();
                });
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            services.AddElasticsearch(Configuration);

            services.AddMassTransit(x =>
            {
                x.AddConsumer <MongoConsumer>();
                x.AddConsumer <ElasticSearchConsumer>();

                x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
                {
                    var host = cfg.Host(new Uri(RabbitMQConfig.RabbitMQUri), hst =>
                    {
                        hst.Username(RabbitMQConfig.RabbitMQUserName);
                        hst.Password(RabbitMQConfig.RabbitMQPassword);
                    });

                    cfg.ReceiveEndpoint(host, "demiroren.news", ep =>
                    {
                        ep.ConfigureConsumer <MongoConsumer>(provider);
                        ep.ConfigureConsumer <ElasticSearchConsumer>(provider);
                    });
                }));
            });

            services.AddSingleton <IHostedService, MassTransitConsoleHostedService>();

            // swagger
            services.AddSwaggerGen(n =>
            {
                n.SwaggerDoc("v1", new Info
                {
                    Title       = "News API",
                    Version     = "v1",
                    Description = "News API using MongoDB & Elastic Search & RabbitMQ",
                });
            });
        }
示例#11
0
 public CategoriesService(CategoriesContext dbContext, ILogger <CategoriesService> logger)
 {
     _dbContext = dbContext;
     _logger    = logger;
 }
示例#12
0
 public CategoriesDetailsController(CategoriesContext context)
 {
     _context = context;
 }
示例#13
0
 public CategoryRepository(CategoriesContext appDbContext)
 {
     _appDbContext = appDbContext;
 }
	public CategoriesContext categories() {
		CategoriesContext _localctx = new CategoriesContext(Context, State);
		EnterRule(_localctx, 64, RULE_categories);
		int _la;
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 1224; k_categories();
			State = 1228;
			ErrorHandler.Sync(this);
			_la = TokenStream.La(1);
			while (_la==SCOL) {
				{
				{
				State = 1225; catparam();
				}
				}
				State = 1230;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
			}
			State = 1231; Match(COL);
			State = 1232; text();
			State = 1237;
			ErrorHandler.Sync(this);
			_la = TokenStream.La(1);
			while (_la==COMMA) {
				{
				{
				State = 1233; Match(COMMA);
				State = 1234; text();
				}
				}
				State = 1239;
				ErrorHandler.Sync(this);
				_la = TokenStream.La(1);
			}
			State = 1240; Match(CRLF);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}