public void Nodes_ProvideS3ChunkUploadWebClient()
        {
            // ARRANGE
            DracoonHttpConfig         conf     = new DracoonHttpConfig();
            IRequestBuilder           builder  = new DracoonRequestBuilder(FactoryClients.OAuthMock);
            DracoonWebClientExtension expected = new DracoonWebClientExtension();

            expected.Headers.Add(HttpRequestHeader.UserAgent, conf.UserAgent);
            expected.SetHttpConfigParams(conf);

            // ACT
            WebClient actual = builder.ProvideS3ChunkUploadWebClient();

            // ASSERT
            Assert.Equal(expected, actual, new WebClientComparer());
        }
Ejemplo n.º 2
0
        public void GetUserAvatar()
        {
            // ARRANGE
            Bitmap   image     = new Bitmap(50, 50);
            Graphics imageData = Graphics.FromImage(image);

            imageData.DrawLine(new Pen(Color.Red), 0, 0, 50, 50);
            MemoryStream memoryStream = new MemoryStream();

            byte[] bitmapData;
            using (memoryStream) {
                image.Save(memoryStream, ImageFormat.Bmp);
                bitmapData = memoryStream.ToArray();
            }

            long   id   = 5;
            string uuid = "H7D68J";
            IInternalDracoonClient c = FactoryClients.InternalDracoonClientMock(true);
            DracoonUsersImpl       u = new DracoonUsersImpl(c);

            Mock.Arrange(() => Arg.AnyLong.MustPositive(Arg.AnyString)).DoNothing().Occurs(1);
            Mock.Arrange(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool)).DoNothing().Occurs(1);
            Mock.Arrange(() => c.Builder.GetUserAvatar(Arg.AnyLong, Arg.AnyString)).Returns(FactoryRestSharp.GetUserAvatarMock()).Occurs(1);
            Mock.Arrange(() => c.Executor.DoSyncApiCall <ApiAvatarInfo>(Arg.IsAny <IRestRequest>(), RequestType.GetResourcesAvatar, 0))
            .Returns(FactoryUser.ApiAvatarInfo).Occurs(1);
            Mock.Arrange(() => c.Builder.ProvideAvatarDownloadWebClient()).Returns(() => {
                DracoonWebClientExtension wc = new DracoonWebClientExtension();
                wc.Headers.Add(HttpRequestHeader.UserAgent, new DracoonHttpConfig().UserAgent);
                wc.SetHttpConfigParams(new DracoonHttpConfig());
                return(wc);
            }).Occurs(1);
            Mock.Arrange(() => c.Executor.ExecuteWebClientDownload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(), RequestType.GetResourcesAvatar, null, 0))
            .Returns(bitmapData).Occurs(1);


            // ACT
            Image actual = u.GetUserAvatar(id, uuid);

            // ASSERT
            Assert.NotNull(actual);
            Mock.Assert(() => Arg.AnyLong.MustPositive(Arg.AnyString));
            Mock.Assert(() => Arg.AnyString.MustNotNullOrEmptyOrWhitespace(Arg.AnyString, Arg.AnyBool));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
        }
        public void Nodes_ProvideChunkUploadWebClient()
        {
            // ARRANGE
            int                       length = 54637;
            long                      offset = 5;
            string                    data = "someDataThings!", fileSize = "123";
            DracoonHttpConfig         conf     = new DracoonHttpConfig();
            IRequestBuilder           builder  = new DracoonRequestBuilder(FactoryClients.OAuthMock);
            DracoonWebClientExtension expected = new DracoonWebClientExtension();

            expected.Headers.Add(HttpRequestHeader.ContentRange, "bytes " + offset + "-" + (offset + length) + "/" + fileSize);
            expected.Headers.Add(HttpRequestHeader.ContentType, "multipart/form-data; boundary=" + data);
            expected.Headers.Add(HttpRequestHeader.UserAgent, conf.UserAgent);
            expected.SetHttpConfigParams(conf);

            // ACT
            WebClient actual = builder.ProvideChunkUploadWebClient(length, offset, data, fileSize);

            // ASSERT
            Assert.Equal(expected, actual, new WebClientComparer());
        }
Ejemplo n.º 4
0
        public void UpdateAvatar()
        {
            // ARRANGE
            Bitmap   image     = new Bitmap(50, 50);
            Graphics imageData = Graphics.FromImage(image);

            imageData.DrawLine(new Pen(Color.Red), 0, 0, 50, 50);
            MemoryStream ms = new MemoryStream();

            image.Save(ms, ImageFormat.Bmp);

            AvatarInfo             expected = FactoryUser.AvatarInfo;
            IInternalDracoonClient c        = FactoryClients.InternalDracoonClientMock(true);
            DracoonAccountImpl     a        = new DracoonAccountImpl(c);

            Mock.Arrange(() => c.Builder.ProvideAvatarUploadWebClient(Arg.AnyString)).Returns((string x) => {
                DracoonWebClientExtension wc = new DracoonWebClientExtension();
                wc.Headers.Add(HttpRequestHeader.ContentType, "multipart/form-data; boundary=" + x);
                wc.Headers.Add(ApiConfig.AuthorizationHeader, FactoryClients.OAuthMock.BuildAuthString());
                wc.Headers.Add(HttpRequestHeader.UserAgent, new DracoonHttpConfig().UserAgent);
                wc.SetHttpConfigParams(new DracoonHttpConfig());
                return(wc);
            }).Occurs(1);
            Mock.Arrange(() => c.Executor.ExecuteWebClientChunkUpload(Arg.IsAny <WebClient>(), Arg.IsAny <Uri>(), Arg.IsAny <byte[]>(), RequestType.PostUserAvatar, null, 0))
            .Returns(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(FactoryUser.ApiAvatarInfo))).Occurs(1);
            Mock.Arrange(() => UserMapper.FromApiAvatarInfo(Arg.IsAny <ApiAvatarInfo>())).Returns(FactoryUser.AvatarInfo).Occurs(1);

            // ACT
            AvatarInfo actual = a.UpdateAvatar(Image.FromStream(ms));

            // ASSERT
            Assert.Equal(expected, actual, new AvatarInfoComparer());
            Mock.Assert(() => UserMapper.FromApiAvatarInfo(Arg.IsAny <ApiAvatarInfo>()));
            Mock.Assert(c.Builder);
            Mock.Assert(c.Executor);
            ms.Close();
        }
 private void SetGeneralWebClientValues(DracoonWebClientExtension requestClient)
 {
     requestClient.Headers.Add(HttpRequestHeader.UserAgent, DracoonClient.HttpConfig.UserAgent);
     requestClient.SetHttpConfigParams(DracoonClient.HttpConfig);
 }