Example #1
0
        public async Task SubmissionBodyIdIsUsed()
        {
            var rdDataStorage = new Mock <IRdDataStorage>();
            var obj           = new ClassWithoutId("Bob");
            var submitBody    = new SubmitDataBody(nameof(ClassWithoutId), obj, false, "SubmitBodyID");

            submitBody = JsonConvert.DeserializeObject <SubmitDataBody>(JsonConvert.SerializeObject(submitBody));
            var sut    = new DefaultIdPolicy();
            var actual = await sut.DetermineIdAsync(submitBody, Submitter, rdDataStorage.Object);

            Assert.That(actual.Id, Is.EqualTo(submitBody.Id));
            rdDataStorage.Verify(x => x.GetIdsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Never);
        }
Example #2
0
        public async Task RdDataStorageIdIsUsed()
        {
            var rdDataStorageId     = "RdDataStorageId";
            var idReservationResult = IdReservationResult.Success(rdDataStorageId, false);
            var rdDataStorage       = new Mock <IRdDataStorage>();

            rdDataStorage.Setup(x => x.GetIdsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>())).Returns(Task.FromResult(new List <IdReservationResult> {
                idReservationResult
            }));
            var obj        = new ClassWithoutId("Bob");
            var submitBody = new SubmitDataBody(nameof(ClassWithoutId), obj, false); // ! No ID provided !

            submitBody = JsonConvert.DeserializeObject <SubmitDataBody>(JsonConvert.SerializeObject(submitBody));
            var sut    = new DefaultIdPolicy();
            var actual = await sut.DetermineIdAsync(submitBody, Submitter, rdDataStorage.Object);

            Assert.That(actual.Id, Is.EqualTo(rdDataStorageId));
            rdDataStorage.Verify(x => x.GetIdsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()), Times.Once);
        }