can I use Moq to grab values that are passed into a public method of an object that is not a mock?
By : Valdis Musa
Date : March 29 2020, 07:55 AM
To fix this issue No. Really mocking frameworks fall into 2 camps. The ones that can mock anything and the other than can only mock Interfaces, Abstract/Virtual methods. This is because they use very much a different interception technology. Moq, RhinoMocks etc use Castle's Dynamic Proxy Generator under the hood which all it does create an instance that exposes the same public interface. It uses this to record interactions with that object so you can verify on it. Abstract and Virtual members can be mocked cause it can derive from that class and prevent calls to the base class.
|
grab each tr value and make a object with td values
By : Martyna Pura
Date : March 29 2020, 07:55 AM
help you fix your problem invTrClassesObj.ProductId gives 'push' of undefined becasuse of invTrClassesObj.ProductId is not set yet. I have added code to get your required JSON object output. code :
//confirm button on click actions
$('#btnConfirm').on('click', function () {
var x = document.querySelectorAll(".invTr");
//console.log(x);
var Items = {};
var invTrClassesObj = [];
var _invTrClasses = $('.invTr');
$.each(_invTrClasses, function (i, invTrClasse) {
invTrClassesObj.push(
{
'ProductId':invTrClasse.getAttribute('data-productId'),
'Price': $(this).find("td").eq(2).html(),
'Quantiry':$(this).closest('tr').find(".qty").val()
});
});
console.log(invTrClassesObj);
//console.log(Items); //I want output object like this-> { ProductId:1 { Price:10.00, Quantiry:1 }, ProductId:2 { Price:20.00, Quantiry:3 } }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Title</th>
<th scope="col">Quantity</th>
<th scope="col">Price Per Unit</th>
<th scope="col">Total Price</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr class="invTr" data-productid="1"> <td>lavenda things</td> <td> <input type="number" class="form-control qty" style="width:75px;" pattern="[0-9]" min="1" max="10000" value="1"> </td> <td> 10.00 </td> <td> 20.55 </td> <td>pp</td>
</tr>
<tr class="invTr" data-productid="2"> <td>lavenda things</td> <td> <input type="number" class="form-control qty" style="width:75px;" pattern="[0-9]" min="1" max="10000" value="3"> </td> <td> 20.00 </td> <td> 20.55 </td> <td>pp</td>
</tr>
</tbody>
</table>
<button id="btnConfirm">Confirm</button>
|
wrong count in object and correct way to count same values in between object and arrays
By : user2312297
Date : March 29 2020, 07:55 AM
With these it helps I tried to counts the same values in object and arrays, and it should show the first numbers which show off in arrays to country it in object here is my wrong code and example case: , I think this is what you are looking for. code :
let index = {};
let result = [];
const arrayList = [{
"code": 101,
"name": "banana",
"price": 1000
}, {
"code": 4,
"name": "bluebberries",
"price": 3000
}, {
"code": 900,
"name": "apple",
"price": 300
}];
// here is value of code in object list
const userChoose = [900, 900, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101];
userChoose.forEach(item => {
if(result.some(i => i.id === item) === false) {
let obj = arrayList.find(e => e.id === item);
result.push({
id: item,
count: 0
});
}
result.find(r => r.id === item).count++;
});
console.log(result);
|
Grab values in javascript object with node.js
By : user3669919
Date : March 29 2020, 07:55 AM
it fixes the issue , You can ‘require’ the file then access the value like this: code :
const theData = require(‘./filename.json’);
const value = theData.data.key1;
|
Grab object values during runtime for creating Mock objects required for writing Unit Test
By : dandox
Date : March 29 2020, 07:55 AM
This might help you You can use Object Exporter. Its an extension for Visual studio which will generate C# initialization code from any object in your debugging windows. You can use this generated code in your unit test initialization.
|