Пример #1
0
        public void EnsureUserExistsAsync_UserExists_ReturnedWithoutDbCall()
        {
            IDbContext dbContext = Substitute.For <IDbContext>();
            UserInfo   userInfo  = new UserInfo();

            userInfo.AuthId = Guid.NewGuid().ToString();
            userInfo.Name   = Guid.NewGuid().ToString();
            userInfo.Email  = Guid.NewGuid().ToString();

            UserDbModel userDbModel = new UserDbModel();

            userDbModel.Id     = Guid.NewGuid().ToString();
            userDbModel.AuthId = userInfo.AuthId;

            UserRepository userRepository = Substitute.For <UserRepository>();

            userRepository.GetByAuthIdAsync(dbContext, userInfo.AuthId).Returns(userDbModel);

            IMapper mapper = CreateMapper();

            CreateUserCommand createUserCommand = Substitute.For <CreateUserCommand>();

            UserViewService userViewService = new UserViewService(dbContext, mapper, userRepository, createUserCommand);
            UserViewModel   result          = userViewService.EnsureUserExistsAsync(userInfo).Result;

            Assert.AreEqual(userInfo.AuthId, result.AuthId);
            createUserCommand.DidNotReceive().ExecuteAsync(Arg.Any <IDbContext>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Wait();
        }