예제 #1
0
        public async Task UserClient_GetPoints_ToUserThatDoesExist_ReturnsPoints()
        {
            // arrange
            var amount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = amount
            };

            var getQuery = new UserQuery
            {
                Id = id
            };

            // act
            var addResult = await client.AddPointsAsync(addQuery);

            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, addResult.Status, "AddPoints() failed.");
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(amount, getResult.Amount);
        }
예제 #2
0
        public async Task UserClient_RemovePoints_ToUserThatDoesNotExist_SetsToZero()
        {
            // arrange
            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var removeQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = 100
            };

            var getQuery = new UserQuery
            {
                Id = id
            };

            // act
            var removeResult = await client.RemovePointsAsync(removeQuery);

            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, removeResult.Status, "RemovePoints() failed.");
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(0, getResult.Amount);
        }
예제 #3
0
        public async Task UserClient_AddPoints_ToUserThatDoesExist_ReturnsExtraPoints()
        {
            // arrange
            var startingAmount   = Rng.Next();
            var additionalAmount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var createQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = startingAmount
            };

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = additionalAmount
            };

            // act
            var createResult = await client.AddPointsAsync(createQuery);

            var addResult = await client.AddPointsAsync(addQuery);

            // assert
            Assert.AreEqual(Status.Success, createResult.Status, "AddPoints() failed.");
            Assert.AreEqual(Status.Success, addResult.Status, "AddPoints() failed.");
            Assert.AreEqual(startingAmount + additionalAmount, addResult.Amount);
        }
예제 #4
0
        public override async Task <UserPointsResult> AddPoints(UserPointsQuery request, ServerCallContext context)
        {
            var result = await _database.AddUserPointsAsync(request.Id, request.Amount);

            return(new UserPointsResult
            {
                Status = result.Success ? Status.Success : Status.Failed,
                Amount = result.Value
            });
        }
예제 #5
0
        public override async Task <UserPointsResult> RemovePoints(UserPointsQuery request, ServerCallContext context)
        {
            var result = await _database.RemoveUserPointsAsync(request.Id, request.Amount);

            return(result.Success
                                ? new UserPointsResult {
                Status = Status.Success, Amount = result.Value
            }
                                : new UserPointsResult {
                Status = Status.Failed
            });
        }
예제 #6
0
        // Tyler doesn't get we validate in Skyra, not in here.
        // [Test]
        public async Task UserClient_RemovePoints_WithNegativeAmount_ReturnsFailedStatus()
        {
            // arrange
            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = -10
            };

            // act
            var addResult = await client.AddPointsAsync(addQuery);

            // assert
            Assert.AreEqual(Status.Failed, addResult.Status, "AddPoints() did not fail.");
        }
예제 #7
0
        public async Task UserClient_RemovePoints_ToUserThatHasMoney_ReturnsCorrectAmount()
        {
            // arrange
            var          channel        = GetChannel();
            var          client         = new User.UserClient(channel);
            const string id             = "1";
            const int    startingAmount = 100;
            const int    removeAmount   = 20;

            var addQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = startingAmount
            };

            var removeQuery = new UserPointsQuery
            {
                Id     = id,
                Amount = removeAmount
            };

            var getQuery = new UserQuery
            {
                Id = id
            };

            // act
            var addResult = await client.AddPointsAsync(addQuery);

            var removeResult = await client.RemovePointsAsync(removeQuery);

            var getResult = await client.GetPointsAsync(getQuery);

            // assert
            Assert.AreEqual(Status.Success, addResult.Status, "AddPoints() failed.");
            Assert.AreEqual(Status.Success, removeResult.Status, "RemovePoints() failed.");
            Assert.AreEqual(Status.Success, getResult.Status, "GetPoints() failed.");
            Assert.AreEqual(startingAmount - removeAmount, getResult.Amount);
        }
예제 #8
0
        public async Task UserClient_AddPoints_ToUserThatDoesNotExist_ReturnsSamePoints()
        {
            // arrange
            var amount = Rng.Next();

            var          channel = GetChannel();
            var          client  = new User.UserClient(channel);
            const string id      = "1";

            var query = new UserPointsQuery
            {
                Id     = id,
                Amount = amount
            };

            // act
            var result = await client.AddPointsAsync(query);

            // assert
            Assert.AreEqual(Status.Success, result.Status, "AddPoints() failed.");
            Assert.AreEqual(amount, result.Amount);
        }