示例#1
0
 public static void SetupData(IQueryable <ApplicationUser> data, UnitTestHandle testHandle)
 {
     testHandle.MockSet.As <IQueryable <ApplicationUser> >().Setup(m => m.Provider).Returns(data.Provider);
     testHandle.MockSet.As <IQueryable <ApplicationUser> >().Setup(m => m.Expression).Returns(data.Expression);
     testHandle.MockSet.As <IQueryable <ApplicationUser> >().Setup(m => m.ElementType).Returns(data.ElementType);
     testHandle.MockSet.As <IQueryable <ApplicationUser> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
 }
        public void SetNullAttending()
        {
            //Arrange
            using var handle = new UnitTestHandle();

            var command = new SetUserAttendingCommand("mockId");

            var commandHandler = new SetUserAttendingCommandHandler(handle.MockContext.Object);

            Assert.ThrowsAsync <InvalidOperationException>(async() =>
                                                           await commandHandler.Handle(command, CancellationToken.None));
        }
        public async Task SetExistingUserAttendingWithDateTime()
        {
            //Arrange

            using var handle = new UnitTestHandle();
            var user = new ApplicationUser(DanceGender.Male)
            {
                Levels = new List <string> {
                    Level.Advanced
                },
                Id = "mockId"
            };

            handle.MockSet.Setup(m => m.FindAsync(It.IsAny <string>(), It.IsAny <CancellationToken>())).Returns(new ValueTask <ApplicationUser>(user));

            var time = DateTime.Now;

            var command = new SetUserAttendingCommand("mockId")
            {
                Attending = new Attending(time)
                {
                    Levels = new List <string> {
                        Level.Advanced
                    }
                }
            };

            var commandHandler = new SetUserAttendingCommandHandler(handle.MockContext.Object);

            //Act
            var x = await commandHandler.Handle(command, new CancellationToken());

            //Assert
            Assert.AreNotEqual(null, user.Attending);
            Assert.AreEqual(time, user.Attending !.Date);
        }