using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Timeline.Controllers; using Timeline.Services; using Moq; using Microsoft.Extensions.Logging.Abstractions; using Xunit; using FluentAssertions; using Microsoft.AspNetCore.Mvc; using Timeline.Filters; using Timeline.Tests.Helpers; using Timeline.Models.Validation; using System.Reflection; using Microsoft.AspNetCore.Authorization; using Timeline.Models.Http; namespace Timeline.Tests.Controllers { public class PersonalTimelineControllerTest : IDisposable { private readonly Mock _service; private readonly PersonalTimelineController _controller; public PersonalTimelineControllerTest() { _service = new Mock(); _controller = new PersonalTimelineController(NullLogger.Instance, _service.Object); } public void Dispose() { _controller.Dispose(); } [Fact] public void AttributeTest() { static void AssertUsernameParameter(MethodInfo m) { m.GetParameter("username") .Should().BeDecoratedWith() .And.BeDecoratedWith(); } static void AssertBodyParamter(MethodInfo m) { var p = m.GetParameter("body"); p.Should().BeDecoratedWith(); p.ParameterType.Should().Be(typeof(TBody)); } var type = typeof(PersonalTimelineController); type.Should().BeDecoratedWith(); { var m = type.GetMethod(nameof(PersonalTimelineController.TimelineGet)); m.Should().BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); } { var m = type.GetMethod(nameof(PersonalTimelineController.PostsGet)); m.Should().BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); } { var m = type.GetMethod(nameof(PersonalTimelineController.TimelinePost)); m.Should().BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); AssertBodyParamter(m); } { var m = type.GetMethod(nameof(PersonalTimelineController.TimelinePostDelete)); m.Should().BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); AssertBodyParamter(m); } { var m = type.GetMethod(nameof(PersonalTimelineController.TimelineChangeProperty)); m.Should().BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); AssertBodyParamter(m); } { var m = type.GetMethod(nameof(PersonalTimelineController.TimelineChangeMember)); m.Should().BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith() .And.BeDecoratedWith(); AssertUsernameParameter(m); AssertBodyParamter(m); } } } }