public async Task Should_Get_Cat_By_Id()
        {
            var cat         = Cats.FirstOrDefault();
            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Name.Should().Be(cat.Name);
        }
        public async Task GetAll_SpecificCatExists_Successful()
        {
            var cat  = Cats.FirstOrDefault();
            var cats = await CatRepository.GetAll();

            cats.FirstOrDefault(x => x.Name == cat.Name).Should().NotBeNull();
        }
示例#3
0
 public CatService(CatRepository repository)
 {
     _repository = repository;
     _mapper     = new MapperConfiguration(cfg => {
         cfg.CreateMap <Cat, CatViewModel>();
     }).CreateMapper();
 }
示例#4
0
        public async Task CatById_ForId_Successful()
        {
            var cat         = TestData.Cats.FirstOrDefault();
            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Name.Should().Be(cat.Name);
        }
        public async Task Should_Contain_Specific_Cat()
        {
            var cat  = Cats.FirstOrDefault();
            var cats = await CatRepository.GetAllAsync();

            cats.FirstOrDefault(x => x.Name == cat.Name).Should().NotBeNull();
        }
        public async Task CatBySecondaryId_ForSecondaryId_Successful()
        {
            var cat         = Cats.FirstOrDefault();
            var existingCat = await CatRepository.GetBySecondaryId(cat.SecondaryId);

            existingCat.Name.Should().Be(cat.Name);
        }
示例#7
0
        public CatsViewModel()
        {
            Cats        = new ObservableCollection <Cat>();
            _repository = new CatRepository();

            InitializeCommands();
        }
示例#8
0
        public CatViewModel()
        {
            catRepo = new CatRepository();

            cats = new ObservableCollection <Cat>();
            LoadData();
        }
 public void Setup()
 {
     log4net.Config.XmlConfigurator.Configure();
     unitOfWorkFactory = ObjectContainer.Get<UnitOfWorkFactory>();
     catRepository = ObjectContainer.Get<CatRepository>();
     ownerRepository = ObjectContainer.Get<OwnerRepository>();
 }
示例#10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSignalR();

            services.AddMvc(options =>
            {
                var policy = new AuthorizationPolicyBuilder()
                             .RequireAuthenticatedUser()
                             .Build();
                options.Filters.Add(new AuthorizeFilter(policy));
            })
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddRazorOptions(options => options.AllowRecompilingViewsOnFileChange = true);

            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services
            .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>
            {
                options.LoginPath   = "/Home/Login";
                options.LogoutPath  = "/Home/Logout";
                options.Cookie.Path = "/";
            });

            var catRepo = new CatRepository();

            services.AddSingleton(typeof(IRepository <Cat>), catRepo);
            services.AddSingleton(typeof(Cache));

            if (CurrentEnvironment.IsDevelopment())
            {
                services.AddSwaggerDocument(config =>
                {
                    config.PostProcess = document =>
                    {
                        document.Info.Version     = "v1";
                        document.Info.Title       = "CATS API";
                        document.Info.Description = "An API To Manage All Cats Everywhere";
                        document.Info.Contact     = new NSwag.SwaggerContact
                        {
                            Name  = "Matthew Fitzpatrick",
                            Email = string.Empty,
                            Url   = "https://github.com/thefnordling"
                        };
                        document.Info.License = new NSwag.SwaggerLicense
                        {
                            Name = "MIT LICENSE",
                            Url  = "https://github.com/thefnordling/cats/blob/master/LICENSE"
                        };
                    };
                });
            }
        }
        public async Task Create_Cat_Successful()
        {
            var cat = new Cat(Guid.NewGuid().ToString(), Ability.Napping);

            Cats.Add(cat);
            await CatRepository.Create(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
        public async Task Update_Cat_Successful()
        {
            var cat = Cats.FirstOrDefault();

            cat.Name = Guid.NewGuid().ToString();

            await CatRepository.Update(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
        public async Task Should_Add_A_Cat()
        {
            var cat = new Cat {
                Name = Guid.NewGuid().ToString(), Ability = Ability.Napping
            };

            Cats.Add(cat);
            await CatRepository.AddAsync(cat);

            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
示例#14
0
        public async Task Delete_Cat_Successful()
        {
            var cat = TestData.Cats.FirstOrDefault();

            cat.Name = Guid.NewGuid().ToString();

            await CatRepository.Delete(cat.Id);

            TestData.Cats.Remove(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Should().BeNull();
        }
示例#15
0
 public BookViewModel()
 {
     bookRepo      = new BookRepository();
     catRepo       = new CatRepository();
     subCatRepo    = new SubCatRepository();
     recommendRepo = new RecommendRepository();
     books         = new ObservableCollection <Book>();
     cats          = new ObservableCollection <Cat>();
     subCats       = new ObservableCollection <SubCat>();
     recommendList = new ObservableCollection <Recommend>();
     paging        = new Paging();
     pageList      = new ObservableCollection <int>();
     LoadData(1);
 }
        public async Task Should_Delete_A_Cat()
        {
            var cat = Cats.FirstOrDefault();

            cat.Name = Guid.NewGuid().ToString();

            await CatRepository.DeleteAsync(cat);

            Cats.Remove(cat);

            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Should().BeNull();
        }
示例#17
0
        private static void InitialiseRepositories()
        {
            var sqlConnection = ConfigurationManager.ConnectionStrings["PetAdoptionContextConnection"].ConnectionString;

            var builder = new DbContextOptionsBuilder <PetAdoptionContext>();

            builder.UseSqlServer(sqlConnection);

            var petAdoptionContext = new PetAdoptionContext(builder.Options);

            //DbInitialiser.Initialize(petAdoptionContext);

            _dogRepository = new DogRepository(petAdoptionContext); // new Context.PetAdoptionContext(null, null));
            _catRepository = new CatRepository(petAdoptionContext); // new Context.PetAdoptionContext(null, null));
        }
示例#18
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers().AddJsonOptions(opt =>
            {
                opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
            });

            var userRepository       = new UserRepository(Configuration.GetConnectionString("CatFeedingDB"));
            var catRepository        = new CatRepository(Configuration.GetConnectionString("CatFeedingDB"));
            var statisticRepository  = new StatisticRepository(Configuration.GetConnectionString("CatFeedingDB"));
            var catSharingRepository = new CatSharingRepository(Configuration.GetConnectionString("CatFeedingDB"));
            var catFeedingRepository = new CatFeedingRepository(Configuration.GetConnectionString("CatFeedingDB"));
            var statisticCalculation = new StatisticCalculation(Configuration.GetConnectionString("CatFeedingDB"));

            services.AddScoped <IUserEntrance>(userEntrance => new UserEntranceProvider(userRepository, new HashWithSaltProtector(10), new Mapper()));
            services.AddScoped <IUserCRUDService>(userCRUDservice => new UserCRUDService(userRepository, new HashWithSaltProtector(10), new Mapper()));
            services.AddScoped <IStatisticCalculation>(statistiCalculation => statisticCalculation);
            services.AddScoped <IStatisticService>(statisticCRUDService => new StatisticService(statisticRepository, statisticCalculation, new Mapper()));
            services.AddScoped <ICatSharingService>(catSharingService => new CatSharingService(catSharingRepository, catRepository, userRepository, new Mapper()));
            services.AddScoped <ICatCRUDService>(catCRUDService => new CatCRUDService(catRepository, catSharingRepository, userRepository, new Mapper()));
            services.AddScoped <ICatFeedingService>(catFeedingService => new CatFeedingService(catFeedingRepository, catRepository, userRepository, catSharingRepository, new Mapper()));
            services.AddScoped <IServiceResultStatusToResponseConverter>(responseConverter => new ServiceResultCodeToResponseConverter());
            services.AddScoped <IMapper>(Mapper => new Mapper());

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.RequireHttpsMetadata      = false;
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidIssuer              = "TaskServer",
                    ValidateAudience         = true,
                    ValidAudience            = "http://localhost:44338/",
                    ValidateLifetime         = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("UNBELIEVABLEsecretKEEEEEYYYYYY!!!!!=)")),
                    ValidateIssuerSigningKey = true,
                };
            });

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Tados Test Task", Version = "v1"
                });
                c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
            });
        }
示例#19
0
 public CatsController()
 {
     catRepository = CatRepository.Instance;
 }
示例#20
0
 public CatsController(CatRepository catRepo)
 {
     _catRepo = catRepo;
 }
        public async Task Should_Get_Exactly_3_Cats()
        {
            var results = await CatRepository.GetAllAsync();

            results.Count().Should().BeGreaterThan(0);
        }
示例#22
0
 public CatService(CatRepository repository)
 {
     _repository = repository;
 }
        public async Task GetAll_Gets3Cats_Successful()
        {
            var results = await CatRepository.GetAll();

            results.Count().Should().BeGreaterThan(0);
        }
示例#24
0
 public CreateModel(CatRepository db)
 {
     _db = db;
 }
示例#25
0
 public HomeController(BookRepository bookRepo, CatRepository catRepo, SubCatRepository subCatRepo)
 {
     this.bookRepo   = bookRepo;
     this.catRepo    = catRepo;
     this.subCatRepo = subCatRepo;
 }
示例#26
0
 public CatController()
 {
     catsContext = new CatRepository();
 }
示例#27
0
 public CatService(CatRepository repository, MapperConfig mapper)
 {
     _repository = repository;
     _mapper     = mapper;
 }
示例#28
0
 public MenuViewComponent(CatRepository catRepo)
 {
     this.catRepo = catRepo;
 }
示例#29
0
 public Service1()
 {
     catRepository = new CatRepository();
 }
示例#30
0
        public IHttpActionResult GetCats()
        {
            var rrr = new CatRepository();

            return(Ok(rrr.Get()));
        }
示例#31
0
 public CatController(CatRepository context)
 {
     _context = context;
 }