Exemplo n.º 1
0
        public void Delete_Ok_Test()
        {
            var reservation = _context.Reservations.Take(10).ToList().Last();

            _reservationOperations.DeleteAsync(reservation.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Reservations.Find(reservation.Id));
            }
        }
Exemplo n.º 2
0
        public void Delete_Ok_Test()
        {
            var org = _context.Organizers.Take(10).ToList().Last();

            _organizerOperations.DeleteAsync(org.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Organizers.FirstOrDefault(o => o.Id == org.Id));
            }
        }
Exemplo n.º 3
0
        public void Delete_Ok_Test()
        {
            var activity = _context.Activities.Take(10).ToList().Last();

            _activityOperations.DeleteAsync(activity.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Activities.Find(activity.Id));
            }
        }
Exemplo n.º 4
0
        public void Delete_Ok_Test()
        {
            var city = _context.Cities.ToList().Take(2).Last();

            _cityOperations.DeleteAsync(city.Id).Wait();

            using (var context = new HobbyContext())
            {
                Assert.IsNull(context.Cities.FirstOrDefault(c => c.Id == city.Id));
            }
        }
Exemplo n.º 5
0
        public void Delete_Ok_Test()
        {
            var picture = _context.Pictures.Take(10).ToList().Last();

            _pictureOperations.DeleteAsync(picture.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Pictures.FirstOrDefault(p => p.Id == picture.Id));
            }
        }
Exemplo n.º 6
0
        public void Delete_Ok_Test()
        {
            var review = _context.Reviews.Take(10).ToList().Last();

            _reviewOperations.DeleteAsync(review.Id).Wait();

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Reviews.FirstOrDefault(r => r.Id == review.Id));
            }
        }
Exemplo n.º 7
0
        public void Delete_OK_Test()
        {
            var org = _context.Organizers.Take(10).ToList().Last();

            HttpDelete <string>($"api/organizer/{org.Id}", _admin_token);

            using (var cntx = new HobbyContext())
            {
                Assert.IsNull(cntx.Organizers.FirstOrDefault(o => o.Id == org.Id));
            }
        }
Exemplo n.º 8
0
        public void Delete_Ok_Test()
        {
            var    review = _context.Reviews.Take(10).ToList().Last();
            string url    = $"/api/review/{review.Id}";

            HttpDelete <string>(url, "ABRAKADABRA");

            using (var cntxt = new HobbyContext())
            {
                Assert.IsNull(cntxt.Reviews.FirstOrDefault(r => r.Id == review.Id));
            }
        }
Exemplo n.º 9
0
        public void Delete_NoAdmin_Test()
        {
            var user = _context.Users.First(u => (u.Role != Role.PortalAdmin) && (u.Role != Role.PortalManager));
            var city = _context.Cities.Take(2).ToList().Last();

            HttpDelete <string>($"api/city/{city.Id}", user.AuthToken);

            using (var context = new HobbyContext())
            {
                Assert.IsNull(context.Cities.FirstOrDefault(c => c.Id == city.Id));
            }
        }
Exemplo n.º 10
0
        //[TestMethod]
        public void DeleteByLinkedObject_Ok_Test()
        {
            var activityId = _context.Pictures.Where(p => (p.LinkedObjectType == LinkedObjectType.Activity))
                             .Select(p => p.LinkedObjectId).First();

            _pictureOperations.DeleteByLinkedObject(LinkedObjectType.Activity, activityId).Wait();

            using (var cntxt = new HobbyContext())
            {
                var pictures = cntxt.Pictures.Where(p => (p.LinkedObjectType == LinkedObjectType.Activity) &&
                                                    (p.LinkedObjectId == activityId));
                Assert.IsFalse(pictures.Any());
            }
        }
Exemplo n.º 11
0
        public void HTTP_Logout_Test()
        {
            var user     = _context.Users.First();
            var oldToken = user.AuthToken;

            HttpPut <string>($"api/user/logout", null, oldToken);

            _context.Entry(user).State = EntityState.Modified;

            using (var context = new HobbyContext())
            {
                var updatedUserToken = context.Users.First(u => u.Email == user.Email).AuthToken;
                Assert.AreNotEqual(oldToken, updatedUserToken);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Вызывается каждый раз при поступлении запроса
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            var token = actionContext.Request.Headers.Authorization?.Parameter;

            if (token == null)
            {
                actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                {
                    Content = new StringContent("Token is null")
                };
                return;
            }
            using (var context = new HobbyContext())
            {
                var userOperations = new UserOperations(context);
                var user           = userOperations.GetUserByToken(token);

                if (user == null)
                {
                    actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized)
                    {
                        Content = new StringContent("User with this token is not found")
                    };
                    return;
                }

                if (_roles != null)
                {
                    if (!_roles.Contains(user.Role.ToString()))
                    {
                        actionContext.Response = new HttpResponseMessage(HttpStatusCode.Forbidden)
                        {
                            Content = new StringContent("Your role is too small")
                        };
                        return;
                    }
                }

                var identity = new Identity {
                    Name = user.Email, IsAuthenticated = true
                };
                actionContext.RequestContext.Principal = new GenericPrincipal(identity, new[] { user.Role.ToString() });
            }
        }
Exemplo n.º 13
0
        public void Add_Ok_Test()
        {
            var tempFile = _context.TempFiles.First();
            var activity = _context.Activities.Take(10).ToList().Last();
            var result   = _pictureOperations.AddAsync(tempFile.Id, true, activity.Id, LinkedObjectType.Activity).Result;

            Assert.IsTrue(!String.IsNullOrEmpty(result.Filename));

            using (var cntxt = new HobbyContext())
            {
                var deletedTempFile = cntxt.TempFiles.FirstOrDefaultAsync(tf => tf.Id == tempFile.Id).Result;
                Assert.IsNull(deletedTempFile);
            }

            var tempFileTest = new TempFileOperationsTest();

            tempFileTest.Add_Ok_Test();
            tempFileTest.Add_Ok_Test();
        }
Exemplo n.º 14
0
 public HomeController(HobbyContext context)
 {
     dbContext = context;
 }
Exemplo n.º 15
0
 public UserOperations(HobbyContext context)
 {
     _context           = context;
     _reviewsOperations = new ReviewOperations(_context);
     _voiceOperations   = new VoiceOperations(_context);
 }
Exemplo n.º 16
0
 public InterestOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 17
0
 public HobbiesController(ILogger <HobbiesController> logger, HobbyContext ctx)
 {
     _logger = logger;
     _ctx    = ctx;
 }
Exemplo n.º 18
0
 public TempFileOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 19
0
 public CityOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 20
0
 public BaseTest()
 {
     _context = new HobbyContext();
 }
Exemplo n.º 21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MemberContext ctx, HobbyContext ctx2, CourseContext ctx3)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            ctx.Database.Migrate();
            ctx2.Database.Migrate();
            ctx3.Database.Migrate();
            app.UseOpenApi();
            app.UseSwaggerUi3();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemplo n.º 22
0
 public PictureOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 23
0
 public ReviewOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 24
0
 public ReservationOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 25
0
 public VoiceOperations(HobbyContext context)
 {
     _context = context;
 }
Exemplo n.º 26
0
 public SystemToolsOperations(HobbyContext context, PictureOperations pictureOperations)
 {
     _context           = context;
     _pictureOperations = pictureOperations;
 }
Exemplo n.º 27
0
 public OrganizerOperations(HobbyContext context)
 {
     _context = context;
 }