示例#1
0
        private async void GetBlockMethodReturnsOkResponse()
        {
            //Arrange
            string         data           = Guid.NewGuid().ToString();
            EncryptService encryptService = new EncryptService();
            string         encryptedPass  = encryptService.EncryptData("1111");
            User           user           = new User("Dimitry", "Sukalo", encryptedPass);

            Block    genesisBlock = new Block();
            UserFile userFile     = new UserFile(data, data, new byte[1]);
            Block    block        = new Block(userFile, user, genesisBlock);

            Mock <IQueryable <Block> > blocks = new List <Block>()
            {
                genesisBlock,
                block
            }.AsQueryable().BuildMock();
            Mock <DbSet <Block> > blockMock = new Mock <DbSet <Block> >();

            SetSettingsInDb(blockMock, blocks);

            Mock <IQueryable <User> > users = new List <User>()
            {
                user
            }.AsQueryable().BuildMock();

            Mock <DbSet <User> > usersMock = new Mock <DbSet <User> >();

            SetSettingsInDb(usersMock, users);

            Mock <BlockChainContext> db = new Mock <BlockChainContext>();

            db.Setup(m => m.Blocks).Returns(blockMock.Object);
            db.Setup(m => m.Users).Returns(usersMock.Object);

            Mock <UserManager <User> > userManagerMock = new Mock <UserManager <User> >(new Mock <IUserStore <User> >().Object,
                                                                                        null, null, null, null, null, null, null, null);

            Mock <IHttpContextAccessor> _contextAccessor = new Mock <IHttpContextAccessor>();

            Mock <IUserClaimsPrincipalFactory <User> > _userPrincipalFactory = new Mock <IUserClaimsPrincipalFactory <User> >();
            Mock <SignInManager <User> > signInMock = new Mock <SignInManager <User> >(userManagerMock.Object,
                                                                                       _contextAccessor.Object, _userPrincipalFactory.Object, null, null, null, null);

            Mock <UnitOfWork>     unitMock       = new Mock <UnitOfWork>(db.Object, signInMock.Object, userManagerMock.Object);
            Mock <DecryptService> decryptMock    = new Mock <DecryptService>();
            GetDataService        getDataService = new GetDataService(unitMock.Object, decryptMock.Object);

            //Act
            ResultOfApiRequest <UserFile> result = await getDataService.GetFile(user.Token, "1111", data);

            //Assert
            Assert.NotNull(result);
            Assert.Equal(HttpStatusCode.OK, result?.StatusCode);
        }
示例#2
0
        private async void GetBlocksMethodReturnsBadRequest()
        {
            //Arrange
            Mock <IQueryable <Block> > blocks    = new List <Block>().AsQueryable().BuildMock();
            Mock <DbSet <Block> >      blockMock = new Mock <DbSet <Block> >();

            SetSettingsInDb(blockMock, blocks);
            User user = new User("Dimitry", "Sukalo", "1111");

            Mock <IQueryable <User> > users = new List <User>().AsQueryable().BuildMock();

            Mock <DbSet <User> > usersMock = new Mock <DbSet <User> >();

            SetSettingsInDb(usersMock, users);

            Mock <BlockChainContext> db = new Mock <BlockChainContext>();

            db.Setup(m => m.Blocks).Returns(blockMock.Object);
            db.Setup(m => m.Users).Returns(usersMock.Object);

            Mock <UserManager <User> > userManagerMock = new Mock <UserManager <User> >(new Mock <IUserStore <User> >().Object,
                                                                                        null, null, null, null, null, null, null, null);

            Mock <IHttpContextAccessor> _contextAccessor = new Mock <IHttpContextAccessor>();

            Mock <IUserClaimsPrincipalFactory <User> > _userPrincipalFactory = new Mock <IUserClaimsPrincipalFactory <User> >();
            Mock <SignInManager <User> > signInMock = new Mock <SignInManager <User> >(userManagerMock.Object,
                                                                                       _contextAccessor.Object, _userPrincipalFactory.Object, null, null, null, null);

            Mock <UnitOfWork>     unitMock       = new Mock <UnitOfWork>(db.Object, signInMock.Object, userManagerMock.Object);
            Mock <DecryptService> decryptMock    = new Mock <DecryptService>();
            GetDataService        getDataService = new GetDataService(unitMock.Object, decryptMock.Object);

            //Act
            ResultOfApiRequest <UserFile> result = await getDataService.GetFile(user.Token, user.Password, Guid.NewGuid().ToString());

            //Assert
            Assert.NotNull(result);
            Assert.Equal(HttpStatusCode.BadRequest, result.StatusCode);
        }